Eslint Inheritance around Extends Property - eslint

We have a repo filled with apps linting in all sorts of different directions. We've updated the linting for most of the apps to consolidate and want to take advantage of eslint inheritance/merging of properties, but the order of the extends property is important. How does merging work with extends?
We have a root .eslintrc that has a setup for typescript, which is the majority of our codebase, but in some of the child .eslintrc files we need to change the order of extends to include eslint for vue and the order is important so we've been added root: true to prevent inheritance.
Our root .eslintrc is a basic typescript setup that's used for some apps and all our APIs:
{
"root": true,
"env": {
"browser": true,
"es2021": true,
"jest/globals": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:#typescript-eslint/recommended",
"prettier"
],
"parser": "#typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": ["#typescript-eslint", "jest"],
"rules": {
// ... removed for brevity
},
"overrides": [
// ... removed for brevity
]
}
There are a couple Vue 2.x applications in the repo that have almost identical .eslintrc files except for the extends property which contains plugin:vue/essential between eslint:recommended and plugin:#typescript-eslint/recommended.
Reading the docs and using --print-config can't figure out whether extends overwrites or tries to merge, or whether it's possible to have it override to include plugin:vue/essential at the right index:
{
// Added to prevent inheritance, but want to remove since other than a few
// rules and overrides all the .eslintrc files are almost the same now
// outside the requirement of `plugin:vue/essential`
"root": true,
"globals": {
"_": true
},
"env": {
"browser": true,
"es2021": true,
"jest/globals": true,
"node": true
},
// ------------------
// How does `extends` property merge, or does it overwrite?
"extends": [
"eslint:recommended",
"plugin:vue/essential",
"plugin:#typescript-eslint/recommended",
"prettier"
],
// ------------------
"parser": "vue-eslint-parser",
"parserOptions": {
"parser": "#typescript-eslint/parser",
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": ["vue", "#typescript-eslint", "jest"],
"rules": {
// ... removed for brevity
},
"overrides": [
// ... removed for brevity
],
"settings": {
"import/resolver": {
// ... removed for brevity
}
}
}
If not we'll just keep them as separate files with root: true, and live with the duplication.

Related

ESlint errors while using yarn#berry with create-react-app and TypeScript

recently in project that I'm starting from scratch I met a problem that I can't get quite solved. I'm not an expert in pnp, actually was setting up this for the first time just now.
We decided to use yarn#berry with zero-installs setup, I did also setup an eslint, prettier, husky with commitlint and started the app.
So, after any .tsx file save this error comes up:eslint plugin error
Here is my .eslintrc.json
{
"env": {
"browser": true,
"es2021": true,
"jest": true
},
"extends": [
"react-app",
"react-app/jest",
"airbnb",
"airbnb-typescript",
"plugin:import/typescript"
],
"parser": "#typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": "latest",
"sourceType": "module",
"project": "./tsconfig.json"
},
"plugins": ["react", "#typescript-eslint"],
"rules": {
"react/react-in-jsx-scope": ["off"],
"react/jsx-uses-react": ["off"],
"react/no-array-index-key": ["off"],
"react/jsx-props-no-spreading": ["warn"],
"react/no-unescaped-entities": ["off"],
"react/function-component-definition": [
2,
{
"namedComponents": "arrow-function",
"unnamedComponents": "arrow-function"
}
]
}
}
And when I do install this single library manually it starts to ask for next plugin that ESlint extends from.

Typescript + node js absolute paths. With eslint setup.(Unable to resolve path to module (import/no-unresolved))

I am aware that this question has been asked multiple times however after trying most of them I am unable to make it work for my use case. I am building simple API with Typescript and Node. I have all my code residing in the src folder from the root.
To avoid those annoying ../../ i have configured absolute paths in my tsconfig.json with the following declarations.
"baseUrl": "./",
"paths": {
"*":[
"./src/*"
]
},
So lets say i have a config.ts file, I should be able to access it from 'src/controllers/tickets.controllers.ts' by just calling import config from 'config'
This does not work.
Additionally in my .eslintrc.json file i have added the following declarations as mentioned in many any answers related to this question.
{
"env": {
"es2021": true,
"node": true
},
"extends": [
"airbnb-base"
],
"parser": "#typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module"
},
"plugins": [
"#typescript-eslint"
],
"rules": {
"import/extensions": [
"error",
"ignorePackages",
{
"js": "never",
"ts": "never"
}
]
},
"settings": {
"import/resolver": {
"node": {
"extensions": [
".js",
".ts"
]
}
}
}
}

How i can get warning instead of error in ESLint for no-unused-vars?

How I can get a warning instead of an error while using ESLint?
I use ESLint 6.7.2 version with a plugin for babel and react.
This is my actual .eslintrc.json:
{
"env": {
"browser": true,
"es6": true
},
"extends": [
"eslint:recommended",
"plugin:react/recommended"
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 2018,
"sourceType": "module"
},
"plugins": [
"react"
],
"rules": {
},
"settings": {
"react" : {
"version": "16.7.0"
}
},
"parser": "babel-eslint"
}
I've found the answer:
It enough to add a rule for no-unused-vars:
"rules": {
"no-unused-vars": "warn"
},
Also, restart the server.

Why does `eslint` require babel to support class arrow function?

I have defined an arrow function on my node 12.6.0 application. But when running eslint it reports an error about Parsing error: Unexpected token =. It works if I add "parser": "babel-eslint" on eslint configuration file. I wonder why eslint require babel for that. This syntax is already supported by node 12.6.0.
Below is my eslint configuration file:
{
"env": {
"commonjs": true,
"es6": true,
"node": true,
"jest": true
},
"extends": [
"airbnb-base"
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018
},
"rules": {
},
"parser": "babel-eslint"
}

eslint-plugin-angular TypeError: Cannot read property 'johnpapa' of undefined

I've installed eslint-plugin-angular globally.
eg:
npm install -g eslint
npm install -g eslint-plugin-angular
According to http://eslint.org/docs/user-guide/configuring using .json files is an option.
Here's my .eslintrc.json file.
json
{
"env" : {
"browser": true,
"jquery": true
},
"plugins": [
"angular"
],
"extends": [
"eslint:recommended",
"plugin:angular/johnpapa"
],
"rules": {
"semi": ["error", "always"]
}
}
The main error I'm running into is this:
TypeError: Cannot read property 'johnpapa' of undefined
Looking at the documentation: https://github.com/Gillespie59/eslint-plugin-angular#usage-without-shareable-config
I can't see why plugin:angular/johnpapa wouldn't work. Do you have to use .yml?
Please see the changed .eslintrc.json below.
{
"env": {
"browser": true,
"es6": true
},
"globals": {
"angular": true,
"require": true
},
"parserOptions": {
"sourceType": "module"
},
"extends": [
"eslint:recommended",
"plugin:angular/johnpapa"
],
"rules": { /* rules here */ }
}

Resources