Initial Commit, eslint rules
This commit is contained in:
commit
7b9db430ea
16 changed files with 2365 additions and 0 deletions
41
.gitignore
vendored
Normal file
41
.gitignore
vendored
Normal file
|
@ -0,0 +1,41 @@
|
|||
# compiled output
|
||||
/dist
|
||||
/lib
|
||||
/node_modules
|
||||
*.tgz
|
||||
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
|
||||
# OS
|
||||
.DS_Store
|
||||
|
||||
# Tests
|
||||
/coverage
|
||||
/.nyc_output
|
||||
|
||||
# IDEs and editors
|
||||
/.idea
|
||||
.project
|
||||
.classpath
|
||||
.c9/
|
||||
*.launch
|
||||
.settings/
|
||||
*.sublime-workspace
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
*.iml
|
||||
|
||||
# .env local files
|
||||
.env.development.local
|
||||
.env.local
|
||||
.env.production.local
|
||||
.env.test.local
|
69
README.md
Normal file
69
README.md
Normal file
|
@ -0,0 +1,69 @@
|
|||
# Eslint Config
|
||||
|
||||
# Notable linting rules
|
||||
- No default exports
|
||||
- No relative imports from other modules, imports must be exported in an index file
|
||||
- Index files only contain imports/exports, no other code
|
||||
|
||||
# Usage
|
||||
|
||||
## base
|
||||
|
||||
Base is used for node/typescript and excludes react specific settings.
|
||||
|
||||
```
|
||||
npm i @ringofstorms/eslint-config \
|
||||
@typescript-eslint/eslint-plugin \
|
||||
eslint \
|
||||
eslint-plugin-eslint-comments \
|
||||
eslint-plugin-import \
|
||||
eslint-plugin-new-with-error \
|
||||
eslint-plugin-prettier \
|
||||
prettier \
|
||||
--save-dev
|
||||
```
|
||||
|
||||
In your .eslintrc
|
||||
```
|
||||
{
|
||||
extends: ["@ringofstorms/eslint-config/base"],
|
||||
}
|
||||
```
|
||||
|
||||
## react
|
||||
React is for react/typescript and is base + react specific settings.
|
||||
|
||||
```
|
||||
npm i @ringofstorms/eslint-config \
|
||||
@typescript-eslint/eslint-plugin \
|
||||
eslint \
|
||||
eslint-plugin-eslint-comments \
|
||||
eslint-plugin-import \
|
||||
eslint-plugin-new-with-error \
|
||||
eslint-plugin-prettier \
|
||||
prettier \
|
||||
eslint-plugin-css-modules \
|
||||
eslint-plugin-react \
|
||||
eslint-plugin-react-hooks \
|
||||
--save-dev
|
||||
```
|
||||
|
||||
In your .eslintrc
|
||||
```
|
||||
{
|
||||
extends: ["@ringofstorms/eslint-config/react"],
|
||||
}
|
||||
```
|
||||
|
||||
# Common rule overrides
|
||||
|
||||
```
|
||||
{
|
||||
rules: {
|
||||
// This will differ for every project and may not even need any settings
|
||||
"import/no-internal-modules": ["error", {
|
||||
allow: ["rxjs/**", "uuid/**", "@nestjs/**"]
|
||||
}],
|
||||
},
|
||||
}
|
||||
```
|
37
base.js
Normal file
37
base.js
Normal file
|
@ -0,0 +1,37 @@
|
|||
module.exports = {
|
||||
parser: '@typescript-eslint/parser',
|
||||
plugins: [
|
||||
'@typescript-eslint',
|
||||
'prettier',
|
||||
'import',
|
||||
'eslint-comments',
|
||||
'new-with-error',
|
||||
],
|
||||
extends: [
|
||||
'eslint:recommended',
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
'plugin:import/errors',
|
||||
'plugin:import/typescript',
|
||||
'plugin:eslint-comments/recommended',
|
||||
'prettier',
|
||||
'prettier/@typescript-eslint',
|
||||
],
|
||||
env: {
|
||||
node: true,
|
||||
jest: true,
|
||||
es6: true,
|
||||
},
|
||||
globals: {
|
||||
process: true,
|
||||
},
|
||||
settings: {
|
||||
...require('./src/base/settings/import'),
|
||||
},
|
||||
rules: {
|
||||
...require('./src/base/rules/eslint'),
|
||||
...require('./src/base/rules/import'),
|
||||
...require('./src/base/rules/new-with-error'),
|
||||
...require('./src/base/rules/prettier'),
|
||||
...require('./src/base/rules/typescript-eslint'),
|
||||
}
|
||||
};
|
2012
package-lock.json
generated
Normal file
2012
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
59
package.json
Normal file
59
package.json
Normal file
|
@ -0,0 +1,59 @@
|
|||
{
|
||||
"name": "@ringofstorms/eslint-config",
|
||||
"version": "0.1.0",
|
||||
"description": "Opinionated eslint configuration for node typescript projects",
|
||||
"main": "base.js",
|
||||
"files": [
|
||||
"src",
|
||||
"base.js",
|
||||
"react.js"
|
||||
],
|
||||
"author": "Josh (RingOfStorms)",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@typescript-eslint/parser": ">= 4",
|
||||
"eslint-config-prettier": ">= 7",
|
||||
"eslint-config-react": ">= 1",
|
||||
"eslint-import-resolver-typescript": ">= 2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@typescript-eslint/eslint-plugin": ">= 4",
|
||||
"eslint": ">= 7",
|
||||
"eslint-plugin-eslint-comments": ">= 3",
|
||||
"eslint-plugin-import": ">= 2",
|
||||
"eslint-plugin-new-with-error": ">= 2",
|
||||
"eslint-plugin-prettier": ">= 3",
|
||||
"prettier": ">= 2",
|
||||
"eslint-plugin-css-modules": ">= 2",
|
||||
"eslint-plugin-react": ">= 7",
|
||||
"eslint-plugin-react-hooks": ">= 3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@typescript-eslint/eslint-plugin": ">= 4",
|
||||
"eslint": ">= 7",
|
||||
"eslint-plugin-eslint-comments": ">= 3",
|
||||
"eslint-plugin-import": ">= 2",
|
||||
"eslint-plugin-new-with-error": ">= 2",
|
||||
"eslint-plugin-prettier": ">= 3",
|
||||
"prettier": ">= 2",
|
||||
"eslint-plugin-css-modules": ">= 2",
|
||||
"eslint-plugin-react": ">= 7",
|
||||
"eslint-plugin-react-hooks": ">= 3"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/RingOfStorms/TODO"
|
||||
},
|
||||
"readmeFilename": "README.md",
|
||||
"keywords": [
|
||||
"eslint",
|
||||
"lint",
|
||||
"lintint",
|
||||
"node",
|
||||
"react",
|
||||
"typescript",
|
||||
"backend",
|
||||
"code",
|
||||
"style"
|
||||
]
|
||||
}
|
33
react.js
vendored
Normal file
33
react.js
vendored
Normal file
|
@ -0,0 +1,33 @@
|
|||
module.exports = {
|
||||
plugins: [
|
||||
'react',
|
||||
'css-modules',
|
||||
'react-hooks',
|
||||
],
|
||||
extends: [
|
||||
'@ringofstorms/eslint-config/base',
|
||||
'plugin:react/recommended',
|
||||
'plugin:import/react',
|
||||
'plugin:css-modules/recommended',
|
||||
'prettier/react',
|
||||
],
|
||||
env: {
|
||||
browser: true,
|
||||
jasmine: true,
|
||||
jest: true,
|
||||
es6: true,
|
||||
},
|
||||
globals: {
|
||||
process: true,
|
||||
},
|
||||
settings: {
|
||||
...require('./src/react/settings/react'),
|
||||
},
|
||||
overrides: [
|
||||
...require('./src/react/overrides'),
|
||||
],
|
||||
rules: {
|
||||
...require('./src/react/rules/react'),
|
||||
...require('./src/react/rules/react-hooks'),
|
||||
},
|
||||
}
|
8
src/base/rules/eslint.js
Normal file
8
src/base/rules/eslint.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
module.exports = {
|
||||
// === DISABLED ===
|
||||
// ==== ERRORS ====
|
||||
curly: 'error',
|
||||
'sort-imports': ['error', {
|
||||
ignoreDeclarationSort: true
|
||||
}],
|
||||
};
|
18
src/base/rules/import.js
Normal file
18
src/base/rules/import.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
module.exports = {
|
||||
// === DISABLED ===
|
||||
// recommended is error, typescript covers this and import/named error has issues
|
||||
'import/named': 'off',
|
||||
// on by default, we do NOT want export default ever.
|
||||
'import/default': 'off',
|
||||
// ==== ERRORS ====
|
||||
// We will not use plugin:import/warnings because we want errors
|
||||
'import/no-duplicates': 'error',
|
||||
'import/order': ['error', { 'newlines-between': 'always' }],
|
||||
// This will differ for every project and may not even need any settings
|
||||
// COPY this to rules of project:
|
||||
// `"import/no-internal-modules": ["error", { allow: ["uuid/**", "@nestjs/**"] }],`
|
||||
'import/no-internal-modules': ['error'],
|
||||
'import/no-cycle': 'error',
|
||||
'import/no-mutable-exports': 'error',
|
||||
'import/no-default-export': 'error',
|
||||
};
|
6
src/base/rules/new-with-error.js
Normal file
6
src/base/rules/new-with-error.js
Normal file
|
@ -0,0 +1,6 @@
|
|||
module.exports = {
|
||||
// === DISABLED ===
|
||||
// ==== ERRORS ====
|
||||
// recommended is warn => enforcing error
|
||||
'new-with-error/new-with-error': 'error',
|
||||
};
|
5
src/base/rules/prettier.js
Normal file
5
src/base/rules/prettier.js
Normal file
|
@ -0,0 +1,5 @@
|
|||
module.exports = {
|
||||
// === DISABLED ===
|
||||
// ==== ERRORS ====
|
||||
'prettier/prettier': 'error',
|
||||
};
|
20
src/base/rules/typescript-eslint.js
Normal file
20
src/base/rules/typescript-eslint.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
module.exports = {
|
||||
// === DISABLED ===
|
||||
// We like parameter properties, so turn them on by turning off this default inverse rule.
|
||||
'@typescript-eslint/no-parameter-properties': 'off',
|
||||
// ==== ERRORS ====
|
||||
// recommended is warn => enforcing error
|
||||
'@typescript-eslint/no-unused-vars': 'error',
|
||||
// recommended is warn => enforcing error
|
||||
'@typescript-eslint/no-explicit-any': 'error',
|
||||
// recommended is warn => enforcing error
|
||||
'@typescript-eslint/explicit-function-return-type': ['error', {
|
||||
allowExpressions: true,
|
||||
allowTypedFunctionExpressions: true
|
||||
}],
|
||||
// recommended does not configure no-public
|
||||
'@typescript-eslint/explicit-member-accessibility': ['error', {
|
||||
accessibility: 'no-public',
|
||||
}],
|
||||
'@typescript-eslint/no-extraneous-class': 'error',
|
||||
};
|
10
src/base/settings/import.js
Normal file
10
src/base/settings/import.js
Normal file
|
@ -0,0 +1,10 @@
|
|||
module.exports = {
|
||||
'import/parsers': {
|
||||
'@typescript-eslint/parser': ['.ts', '.tsx']
|
||||
},
|
||||
'import/resolver': {
|
||||
typescript: {
|
||||
alwaysTryTypes: false,
|
||||
},
|
||||
},
|
||||
};
|
12
src/react/overrides.js
Normal file
12
src/react/overrides.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
module.exports = [
|
||||
{
|
||||
files: ['**/*.tsx'],
|
||||
rules: {
|
||||
// [Plugin] react - disable prop type checks in typescript since we use interfaces
|
||||
'react/prop-types': 'off',
|
||||
|
||||
// Allow ts-ignore in test files for easily faking data and objects
|
||||
'@typescript-eslint/ban-ts-ignore': 'off',
|
||||
},
|
||||
},
|
||||
];
|
6
src/react/rules/react-hooks.js
vendored
Normal file
6
src/react/rules/react-hooks.js
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
module.exports = {
|
||||
// === DISABLED ===
|
||||
// ==== ERRORS ====
|
||||
'react-hooks/rules-of-hooks': 'error',
|
||||
'react-hooks/exhaustive-deps': 'error',
|
||||
};
|
23
src/react/rules/react.js
vendored
Normal file
23
src/react/rules/react.js
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
module.exports = {
|
||||
// === DISABLED ===
|
||||
// This does not play nice with React.memo()
|
||||
'react/display-name': 'off',
|
||||
// ==== ERRORS ====
|
||||
'react/no-access-state-in-setstate': 'error',
|
||||
'react/no-redundant-should-component-update': 'error',
|
||||
'react/no-typos': 'error',
|
||||
'react/no-unsafe': 'error',
|
||||
'react/self-closing-comp': 'error',
|
||||
'react/jsx-no-bind': 'error',
|
||||
'react/jsx-max-depth': ['error', { max: 5 }],
|
||||
'react/jsx-curly-brace-presence': ['error', 'never'],
|
||||
'react/jsx-wrap-multilines': ['error', {
|
||||
declaration: 'parens-new-line',
|
||||
assignment: 'parens-new-line',
|
||||
return: 'parens-new-line',
|
||||
arrow: 'parens-new-line',
|
||||
condition: 'parens-new-line',
|
||||
logical: 'parens-new-line',
|
||||
prop: 'parens-new-line'
|
||||
}],
|
||||
};
|
6
src/react/settings/react.js
vendored
Normal file
6
src/react/settings/react.js
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
module.exports = {
|
||||
react: {
|
||||
pragma: 'React',
|
||||
version: 'detect',
|
||||
},
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue