这是我用字典写成的法典:
class Snake {
constructor(
public x: number, // error x is defined but never used
public y: number, // error y is defined but never used
public size = 10, // error size is assigned a value but never used
public color = (() => {
const tab = new Array(6).fill(0);
return `#${tab.map(() => (Math.random() * 0xF << 0).toString(16)).join( )}`;
})(), // error color is assigned a value but never used
) { }
update() {
const coef = (): number => {
const nb = Math.round(Math.random());
return nb === 0 ? -1 : 1;
};
this.x += Math.random() * 10 * coef();
this.y += Math.random() * 10 * coef();
}
...
I got eslint installed and it tells me for all the variables : is defined but never used and right under it I use them. I think eslint doesn t understand the declaration inside the constructor parentheses but I m not sure. I use this method of declaration very often so if I can fix this it I ll be happy
{
"env": {
"browser": true,
"es2021": true
},
"extends": [
"airbnb-base"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"no-restricted-globals": "off",
"consistent-return": "off",
"no-return-assign": "off",
"prefer-const": "off",
"no-param-reassign": "off",
"block-scoped-var": "off",
"no-use-before-define": "off",
"no-undef": "warn",
"no-unused-vars": "warn",
"no-plusplus": "off",
"no-var": "off",
"vars-on-top": "off",
"indent": [
"error",
4
],
"no-console": "off",
"no-mixed-spaces-and-tabs": "off",
"linebreak-style": "off", window
"class-methods-use-this": "off",
"no-empty": "off",
"no-constant-condition": "off",
"nonblock-statement-body-position": [
"error",
"below"
],
"curly": "off",
"no-useless-constructor": "off",
"no-empty-function": "off",
"no-bitwise": "off"
}
这里是我的先辈,错误来自未使用过的瓦尔斯。