-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Javier Maestre
committed
Oct 24, 2020
1 parent
9bde385
commit c6f8e4d
Showing
17 changed files
with
441 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# EditorConfig is awesome: http://editorconfig.org/ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_size = 2 | ||
indent_style = space | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules/ | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/node_modules | ||
|
||
yarn-error.log | ||
yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module.exports = { | ||
printWidth: 120, | ||
tabWidth: 2, | ||
singleQuote: true, | ||
trailingComma: 'none', | ||
semi: true, | ||
'newline-before-return': true, | ||
'no-duplicate-variable': [true, 'check-parameters'], | ||
'no-var-keyword': true | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module.exports = { | ||
root: true, | ||
parserOptions: { | ||
sourceType: 'module', | ||
ecmaFeatures: { | ||
jsx: true, | ||
modules: true | ||
} | ||
}, | ||
env: { | ||
browser: true, | ||
es6: true | ||
}, | ||
extends: ['airbnb', 'prettier', 'prettier/react', 'prettier/@typescript-eslint'] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module.exports = { | ||
root: true, | ||
parserOptions: { | ||
sourceType: 'module', | ||
ecmaFeatures: { | ||
jsx: true, | ||
modules: true | ||
} | ||
}, | ||
env: { | ||
browser: true, | ||
es6: true | ||
}, | ||
extends: ['airbnb', 'prettier', 'prettier/react'] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module.exports = { | ||
root: true, | ||
parserOptions: { | ||
sourceType: 'module', | ||
ecmaFeatures: { | ||
jsx: true, | ||
modules: true | ||
} | ||
}, | ||
env: { | ||
browser: true, | ||
es6: true | ||
}, | ||
extends: ['airbnb', 'prettier'] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module.exports = { | ||
root: true, | ||
parserOptions: { | ||
sourceType: 'module', | ||
ecmaFeatures: { | ||
jsx: true, | ||
modules: true | ||
} | ||
}, | ||
env: { | ||
browser: true, | ||
es6: true | ||
}, | ||
extends: [], | ||
plugins: ['jsx-a11y'], | ||
globals: {}, | ||
rules: {} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// All the avaible rules in detail: https://eslint.org/docs/rules/ | ||
module.exports = { | ||
extends: ['airbnb'], | ||
rules: { | ||
'comma-dangle': ['error', 'only-multiline'], // Require trailing-comma only on multilines: https://eslint.org/docs/rules/comma-dangle#options-14 | ||
'object-curly-newline': 'off', // Can be managed with prettier rules | ||
'max-len': ['error', { code: 120, tabWidth: 2, ignoreComments: true }], // It's aligned with the config of .prettierrc.js | ||
'implicit-arrow-linebreak': 'off', // Prettier will manage this rule | ||
'function-paren-newline': 'off' // Prettier will manage this rule | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
# ESLint configs | ||
|
||
This project have presets for ESLint which I use in private projects: | ||
|
||
## Available configs | ||
|
||
- `@javiermaestre/eslint-config/a11y` - Accessibility rules from [eslint-plugin-jsx-a11y](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y#readme) | ||
- `@javiermaestre/eslint-config/core` - ESLINT base config from [eslint-config-airbnb](https://github.com/airbnb/javascript) | ||
- `@javiermaestre/eslint-config/react` - Based on React rules of `Airbnb` | ||
- `@javiermaestre/eslint-config/react-hooks` - Based on React Hooks rules of `Airbnb` | ||
- `@javiermaestre/eslint-config/react-typescript` - Based on [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint#readme) | ||
|
||
## Install | ||
|
||
Install as a DEV dependency | ||
|
||
```bash | ||
yarn add --dev @javiermaestre/eslint-config | ||
npm install --D @javiermaestre/eslint-config | ||
``` | ||
|
||
## Extend | ||
|
||
Extend configs creating a `.eslintrc.js` or `eslintrc.json` file on your project: | ||
|
||
```js | ||
// eslintrc.js | ||
module.exports = { | ||
extends: [ | ||
'@javiermaestre/eslint-config/core', | ||
'@javiermaestre/eslint-config/react', | ||
'@javiermaestre/eslint-config/react-hooks', | ||
'@javiermaestre/eslint-config/react-typescript' | ||
] | ||
}; | ||
``` | ||
|
||
```json | ||
// eslintrc.json | ||
{ | ||
"extends": ["@javiermaestre/eslint-config/core", "@javiermaestre/eslint-config/react-typescript"] | ||
} | ||
``` | ||
|
||
Also, you can override and customise rules: | ||
|
||
- Set the config properties of ESLINT, like [`env`](http://eslint.org/docs/user-guide/configuring#specifying-environments) [`parserOptions`](http://eslint.org/docs/user-guide/configuring#specifying-parser-options), | ||
or others as you like ([`ESLINT documentation`](http://eslint.org/docs/user-guide/configuring)) | ||
- Override specific rules for your project | ||
|
||
## Default configs | ||
|
||
This are configs ready to use: | ||
|
||
- Config for JS | ||
|
||
```js | ||
// eslintrc.js | ||
module.exports = { | ||
extends: ['@javiermaestre/eslint-config/core'] | ||
}; | ||
``` | ||
|
||
- Config for Typescript | ||
|
||
```js | ||
// eslintrc.js | ||
module.exports = { | ||
extends: ['@javiermaestre/eslint-config/typescript'] | ||
}; | ||
``` | ||
|
||
- Config for React | ||
|
||
```js | ||
// eslintrc.js | ||
module.exports = { | ||
extends: [ | ||
'@javiermaestre/eslint-config/react' // React package extends from /core | ||
] | ||
}; | ||
``` | ||
|
||
- Config for React with Typescript | ||
|
||
```js | ||
// eslintrc.js | ||
module.exports = { | ||
extends: [ | ||
'@javiermaestre/eslint-config/react-typescript' // React Typescript package extends from /react and /core | ||
] | ||
}; | ||
``` | ||
|
||
- Config for React with Typescript and Hooks | ||
|
||
```js | ||
// eslintrc.js | ||
module.exports = { | ||
extends: [ | ||
'@javiermaestre/eslint-config/react-typescript', // React Typescript package with Hooks extends from /react and /core | ||
'@javiermaestre/eslint-config/react-hooks' | ||
] | ||
}; | ||
``` | ||
|
||
## Extra configuration | ||
|
||
The plugin is ready to work with: | ||
|
||
- Prettier - Adding a `.prettierrc` file | ||
- Editorconfig - Adding a `.editorconfig` file | ||
|
||
You can override the settings on this files | ||
|
||
## Run linter | ||
|
||
- For report | ||
|
||
```bash | ||
eslint --ext .js,.jsx . | ||
``` | ||
|
||
- For auto fixing | ||
|
||
```bash | ||
eslint --ext .js,.jsx . --fix | ||
``` | ||
|
||
## Next steps | ||
|
||
Add support for: | ||
|
||
```js | ||
|
||
// for Node.js projects | ||
'@javiermaestre/eslint-config/node', | ||
|
||
// for Angular projects | ||
'@javiermaestre/eslint-config/angular', | ||
|
||
... | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.exports = { | ||
extends: ['./config/core.js'], | ||
parserOptions: { | ||
sourceType: 'module', | ||
ecmaVersion: 2020 | ||
}, | ||
reportUnusedDisableDirectives: true, | ||
root: true | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"name": "@javiermaestre/eslint-config", | ||
"version": "1.0.0", | ||
"description": "ESLint config for projects (ESLint + Airbnb + TypeScript + Prettier)", | ||
"publishConfig": { | ||
"registry": "https://npm.pkg.github.com/" | ||
}, | ||
"license": "MIT", | ||
"scripts": {}, | ||
"engines": { | ||
"node": ">=10" | ||
}, | ||
"peerDependencies": { | ||
"eslint": "7.x", | ||
"prettier": "2.x", | ||
"typescript": "3.x" | ||
}, | ||
"dependencies": { | ||
"@typescript-eslint/eslint-plugin": "3.8.0", | ||
"@typescript-eslint/parser": "3.8.0", | ||
"eslint-config-airbnb": "18.2.0", | ||
"eslint-config-prettier": "6.11.0", | ||
"eslint-plugin-import": "2.22.0", | ||
"eslint-plugin-jsx-a11y": "6.3.1", | ||
"eslint-plugin-prettier": "3.1.4", | ||
"eslint-plugin-react": "7.20.6", | ||
"eslint-plugin-react-hooks": "4.1.0" | ||
}, | ||
"devDependencies": { | ||
"eslint": "7.x", | ||
"prettier": "2.x", | ||
"typescript": "3.x" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
extends: ['airbnb/hooks'] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
module.exports = { | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
project: './tsconfig.json', | ||
sourceType: 'module', | ||
ecmaFeatures: { | ||
jsx: true, | ||
modules: true | ||
} | ||
}, | ||
env: { | ||
browser: true, | ||
es6: true | ||
}, | ||
extends: [ | ||
'./core.js', | ||
'plugin:@typescript-eslint/recommended', | ||
'plugin:import/typescript', | ||
'./_prettier-react-typescript.js', | ||
'./react.js' | ||
], | ||
plugins: ['import', '@typescript-eslint'], | ||
rules: { | ||
// Import | ||
'import/prefer-default-export': 'off', | ||
'import/extensions': [ | ||
'error', | ||
'ignorePackages', | ||
{ | ||
js: 'never', | ||
mjs: 'never', | ||
jsx: 'never', | ||
ts: 'never', | ||
tsx: 'never' | ||
} | ||
], | ||
// TypeScript | ||
'@typescript-eslint/no-unused-vars': 'error', | ||
'@typescript-eslint/explicit-member-accessibility': 'off', | ||
'@typescript-eslint/no-object-literal-type-assertion': 'off', | ||
'@typescript-eslint/prefer-interface': 'off', | ||
'@typescript-eslint/camelcase': 'off', | ||
'@typescript-eslint/explicit-function-return-type': 'off', | ||
'@typescript-eslint/no-explicit-any': 'off', | ||
// Other | ||
radix: 'warn' | ||
}, | ||
settings: { | ||
'import/resolver': { | ||
node: { | ||
extensions: ['.js', '.jsx', '.ts', '.tsx'], | ||
moduleDirectory: ['node_modules', 'src'] | ||
} | ||
} | ||
} | ||
}; |
Oops, something went wrong.