|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
1.6 KB
|
| Line | |
|---|
| 1 | /**
|
|---|
| 2 | * @fileoverview enforce default parameters to be last
|
|---|
| 3 | * @author Chiawen Chen
|
|---|
| 4 | */
|
|---|
| 5 |
|
|---|
| 6 | "use strict";
|
|---|
| 7 |
|
|---|
| 8 | /** @type {import('../shared/types').Rule} */
|
|---|
| 9 | module.exports = {
|
|---|
| 10 | meta: {
|
|---|
| 11 | type: "suggestion",
|
|---|
| 12 |
|
|---|
| 13 | docs: {
|
|---|
| 14 | description: "Enforce default parameters to be last",
|
|---|
| 15 | recommended: false,
|
|---|
| 16 | url: "https://eslint.org/docs/latest/rules/default-param-last"
|
|---|
| 17 | },
|
|---|
| 18 |
|
|---|
| 19 | schema: [],
|
|---|
| 20 |
|
|---|
| 21 | messages: {
|
|---|
| 22 | shouldBeLast: "Default parameters should be last."
|
|---|
| 23 | }
|
|---|
| 24 | },
|
|---|
| 25 |
|
|---|
| 26 | create(context) {
|
|---|
| 27 |
|
|---|
| 28 | /**
|
|---|
| 29 | * Handler for function contexts.
|
|---|
| 30 | * @param {ASTNode} node function node
|
|---|
| 31 | * @returns {void}
|
|---|
| 32 | */
|
|---|
| 33 | function handleFunction(node) {
|
|---|
| 34 | let hasSeenPlainParam = false;
|
|---|
| 35 |
|
|---|
| 36 | for (let i = node.params.length - 1; i >= 0; i -= 1) {
|
|---|
| 37 | const param = node.params[i];
|
|---|
| 38 |
|
|---|
| 39 | if (
|
|---|
| 40 | param.type !== "AssignmentPattern" &&
|
|---|
| 41 | param.type !== "RestElement"
|
|---|
| 42 | ) {
|
|---|
| 43 | hasSeenPlainParam = true;
|
|---|
| 44 | continue;
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | if (hasSeenPlainParam && param.type === "AssignmentPattern") {
|
|---|
| 48 | context.report({
|
|---|
| 49 | node: param,
|
|---|
| 50 | messageId: "shouldBeLast"
|
|---|
| 51 | });
|
|---|
| 52 | }
|
|---|
| 53 | }
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | return {
|
|---|
| 57 | FunctionDeclaration: handleFunction,
|
|---|
| 58 | FunctionExpression: handleFunction,
|
|---|
| 59 | ArrowFunctionExpression: handleFunction
|
|---|
| 60 | };
|
|---|
| 61 | }
|
|---|
| 62 | };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.