16
loading...
This website collects cookies to deliver better user experience
├──.eslintrc.json // ESLint configuration
├── node_modules
├── package-lock.json
├── package.json
└── src
└── index.js
src/index.js
like thisnpx eslint src
/Users/xxx/foo/src/index.js
1:7 error 'foo' is assigned a value but never used no-unused-vars
src/index.js
.const foo = () => "baz"
foo
is defined but it’s not called from anywhere. That’s why the error happened.no-unused-vars
that we saw above is one of the rules.const hoge = 0;
is like this. (You can see AST easily with AST Explorer){
"type": "File",
"start": 0,
"end": 16,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 0
}
},
"errors": [],
"program": {
"type": "Program",
"start": 0,
"end": 16,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 0
}
},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "VariableDeclaration",
"start": 0,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 15
}
},
"declarations": [
{
"type": "VariableDeclarator",
"start": 6,
"end": 14,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 14
}
},
"id": {
"type": "Identifier",
"start": 6,
"end": 10,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 10
},
"identifierName": "hoge"
},
"name": "hoge"
},
"init": {
"type": "NumericLiteral",
"start": 13,
"end": 14,
"loc": {
"start": {
"line": 1,
"column": 13
},
"end": {
"line": 1,
"column": 14
}
},
"extra": {
"rawValue": 0,
"raw": "0"
},
"value": 0
}
}
],
"kind": "const"
}
],
"directives": []
},
"comments": []
}
├── lib
│ └── index.js
├── package.json
// Todo: will change variable name later
let hoge = 0;
/Users/xxx/eslint-test/src/index.js
1:1 error Later becomes never later-becomes-never/no-todo
no-todo
which comes from later-becomes-never
plugin.lib/index.js
.module.exports = {
rules: {
"no-todo": {
create: function (context) {
return {
Program: (node) => {
node.comments.forEach((comment) => {
if (comment.value.toLowerCase().indexOf("todo") !== -1) {
context.report({
loc: comment.loc,
message: "Later becomes never",
});
}
});
},
};
},
},
},
};
// Todo: will change variable name later
let hoge = 0;
// doit
/Users/xxx/eslint-test/index.js
1:1 error Later becomes never later-becomes-never/no-todo
✖ 1 problem (1 error, 0 warnings)
16