update to latests
This commit is contained in:
parent
71c67f66de
commit
af0c093759
19 changed files with 2194 additions and 1018 deletions
34
README.md
34
README.md
|
@ -1,6 +1,7 @@
|
|||
# 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
|
||||
|
@ -14,20 +15,21 @@ Base is used for node/typescript and excludes react specific settings.
|
|||
```
|
||||
npm i @ringofstorms/eslint-config \
|
||||
@typescript-eslint/eslint-plugin \
|
||||
@typescript-eslint/parser \
|
||||
eslint \
|
||||
eslint-config-prettier \
|
||||
eslint-import-resolver-typescript \
|
||||
eslint-plugin-eslint-comments \
|
||||
eslint-plugin-filenames \
|
||||
eslint-plugin-import \
|
||||
eslint-plugin-new-with-error \
|
||||
eslint-plugin-prettier \
|
||||
@typescript-eslint/parser \
|
||||
eslint-config-prettier \
|
||||
eslint-config-react \
|
||||
eslint-import-resolver-typescript \
|
||||
prettier \
|
||||
--save-dev
|
||||
```
|
||||
|
||||
In your .eslintrc
|
||||
|
||||
```
|
||||
{
|
||||
extends: ["@ringofstorms/eslint-config/base"],
|
||||
|
@ -35,28 +37,31 @@ In your .eslintrc
|
|||
```
|
||||
|
||||
## 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 \
|
||||
@typescript-eslint/parser \
|
||||
eslint \
|
||||
eslint-config-prettier \
|
||||
eslint-config-react \
|
||||
eslint-import-resolver-typescript \
|
||||
eslint-plugin-css-modules \
|
||||
eslint-plugin-eslint-comments \
|
||||
eslint-plugin-filenames \
|
||||
eslint-plugin-import \
|
||||
eslint-plugin-new-with-error \
|
||||
eslint-plugin-prettier \
|
||||
eslint-plugin-react \
|
||||
eslint-plugin-react-hooks \
|
||||
prettier \
|
||||
--save-dev
|
||||
```
|
||||
|
||||
In your .eslintrc
|
||||
|
||||
```
|
||||
{
|
||||
extends: ["@ringofstorms/eslint-config/react"],
|
||||
|
@ -66,6 +71,7 @@ In your .eslintrc
|
|||
## prettier settings
|
||||
|
||||
Create `prettier.config.js` file in root of project with this content:
|
||||
|
||||
```
|
||||
module.exports = require('@ringofstorms/eslint-config').prettierConfig;
|
||||
```
|
||||
|
@ -86,9 +92,11 @@ module.exports = require('@ringofstorms/eslint-config').prettierConfig;
|
|||
# Contributing
|
||||
|
||||
## Packing
|
||||
|
||||
`npm pack`
|
||||
|
||||
## publishing
|
||||
|
||||
if not already done `npm login`
|
||||
|
||||
`npm publish --access public`
|
||||
|
|
47
base.js
47
base.js
|
@ -1,19 +1,20 @@
|
|||
module.exports = {
|
||||
parser: '@typescript-eslint/parser',
|
||||
parser: "@typescript-eslint/parser",
|
||||
plugins: [
|
||||
'@typescript-eslint',
|
||||
'prettier',
|
||||
'import',
|
||||
'eslint-comments',
|
||||
'new-with-error',
|
||||
"@typescript-eslint",
|
||||
"eslint-comments",
|
||||
"filenames",
|
||||
"import",
|
||||
"new-with-error",
|
||||
"prettier",
|
||||
],
|
||||
extends: [
|
||||
'eslint:recommended',
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
'plugin:import/errors',
|
||||
'plugin:import/typescript',
|
||||
'plugin:eslint-comments/recommended',
|
||||
'prettier',
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
"plugin:eslint-comments/recommended",
|
||||
"plugin:import/errors",
|
||||
"plugin:import/typescript",
|
||||
"prettier",
|
||||
],
|
||||
env: {
|
||||
node: true,
|
||||
|
@ -24,21 +25,15 @@ module.exports = {
|
|||
process: true,
|
||||
},
|
||||
settings: {
|
||||
...require('./src/base/settings/import'),
|
||||
...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'),
|
||||
...require("./src/base/rules/eslint"),
|
||||
...require("./src/base/rules/filenames"),
|
||||
...require("./src/base/rules/import"),
|
||||
...require("./src/base/rules/new-with-error"),
|
||||
...require("./src/base/rules/prettier"),
|
||||
...require("./src/base/rules/typescript-eslint"),
|
||||
},
|
||||
overrides: [
|
||||
{
|
||||
files: "prettier.config.js",
|
||||
rules: {
|
||||
"@typescript-eslint/no-var-requires": "off"
|
||||
}
|
||||
}
|
||||
]
|
||||
overrides: [...require("./src/base/overrides")],
|
||||
};
|
||||
|
|
2906
package-lock.json
generated
2906
package-lock.json
generated
File diff suppressed because it is too large
Load diff
43
package.json
43
package.json
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@ringofstorms/eslint-config",
|
||||
"version": "0.2.0",
|
||||
"version": "0.3.0",
|
||||
"description": "Opinionated eslint configuration for node typescript projects",
|
||||
"main": "src/index.js",
|
||||
"files": [
|
||||
|
@ -11,37 +11,42 @@
|
|||
],
|
||||
"author": "Josh (RingOfStorms)",
|
||||
"license": "ISC",
|
||||
"scripts": {
|
||||
"lint:fix": "prettier . --check --write"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@typescript-eslint/parser": ">= 4",
|
||||
"@typescript-eslint/eslint-plugin": ">=5",
|
||||
"@typescript-eslint/parser": ">=4",
|
||||
"eslint": ">=7",
|
||||
"eslint-config-prettier": ">=8",
|
||||
"eslint-config-react": ">= 1",
|
||||
"eslint-import-resolver-typescript": ">= 2",
|
||||
"@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-eslint-comments": ">= 3",
|
||||
"eslint-plugin-filenames": ">=1",
|
||||
"eslint-plugin-import": ">= 2",
|
||||
"eslint-plugin-new-with-error": ">=3",
|
||||
"eslint-plugin-prettier": ">=4",
|
||||
"eslint-plugin-react": ">= 7",
|
||||
"eslint-plugin-react-hooks": ">=4"
|
||||
"eslint-plugin-react-hooks": ">=4",
|
||||
"prettier": ">= 2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@typescript-eslint/parser": ">= 4",
|
||||
"@typescript-eslint/eslint-plugin": ">=5",
|
||||
"@typescript-eslint/parser": ">=4",
|
||||
"eslint": ">=7",
|
||||
"eslint-config-prettier": ">=8",
|
||||
"eslint-config-react": ">= 1",
|
||||
"eslint-import-resolver-typescript": ">= 2",
|
||||
"@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-eslint-comments": ">= 3",
|
||||
"eslint-plugin-filenames": ">=1",
|
||||
"eslint-plugin-import": ">= 2",
|
||||
"eslint-plugin-new-with-error": ">=3",
|
||||
"eslint-plugin-prettier": ">=4",
|
||||
"eslint-plugin-react": ">= 7",
|
||||
"eslint-plugin-react-hooks": ">=4"
|
||||
"eslint-plugin-react-hooks": ">=4",
|
||||
"prettier": ">= 2"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
|
28
react.js
vendored
28
react.js
vendored
|
@ -1,15 +1,11 @@
|
|||
module.exports = {
|
||||
plugins: [
|
||||
'react',
|
||||
'css-modules',
|
||||
'react-hooks',
|
||||
],
|
||||
plugins: ["react", "css-modules", "react-hooks"],
|
||||
extends: [
|
||||
'@ringofstorms/eslint-config/base',
|
||||
'plugin:react/recommended',
|
||||
'plugin:import/react',
|
||||
'plugin:css-modules/recommended',
|
||||
'prettier',
|
||||
"@ringofstorms/eslint-config/base",
|
||||
"plugin:react/recommended",
|
||||
"plugin:import/react",
|
||||
"plugin:css-modules/recommended",
|
||||
"prettier",
|
||||
],
|
||||
env: {
|
||||
browser: true,
|
||||
|
@ -21,13 +17,11 @@ module.exports = {
|
|||
process: true,
|
||||
},
|
||||
settings: {
|
||||
...require('./src/react/settings/react'),
|
||||
...require("./src/react/settings/react"),
|
||||
},
|
||||
overrides: [
|
||||
...require('./src/react/overrides'),
|
||||
],
|
||||
rules: {
|
||||
...require('./src/react/rules/react'),
|
||||
...require('./src/react/rules/react-hooks'),
|
||||
...require("./src/react/rules/react"),
|
||||
...require("./src/react/rules/react-hooks"),
|
||||
},
|
||||
}
|
||||
overrides: [...require("./src/react/overrides")],
|
||||
};
|
||||
|
|
16
src/base/overrides.js
Normal file
16
src/base/overrides.js
Normal file
|
@ -0,0 +1,16 @@
|
|||
module.exports = [
|
||||
{
|
||||
files: ["*.test.ts"],
|
||||
rules: {
|
||||
"require-atomic-updates": "off", // tests do this a lot
|
||||
"no-underscore-dangle": "off", // allow testing private methods
|
||||
"@typescript-eslint/no-empty-function": "off", // allow empty functions in tests, often used in mock implementations
|
||||
},
|
||||
},
|
||||
{
|
||||
files: ["*.js", "prettier.config.js"],
|
||||
rules: {
|
||||
"@typescript-eslint/no-var-requires": "off",
|
||||
},
|
||||
},
|
||||
];
|
|
@ -1,8 +1,12 @@
|
|||
module.exports = {
|
||||
// === DISABLED ===
|
||||
// ==== ERRORS ====
|
||||
curly: 'error',
|
||||
'sort-imports': ['error', {
|
||||
ignoreDeclarationSort: true
|
||||
}],
|
||||
curly: "error",
|
||||
"sort-imports": [
|
||||
"error",
|
||||
{
|
||||
ignoreDeclarationSort: true,
|
||||
},
|
||||
],
|
||||
"no-underscore-dangle": ["error", { allowAfterThis: true }], // using underscores as an alternative to mark methods as private. This way we can still write tests for methods
|
||||
};
|
||||
|
|
7
src/base/rules/filenames.js
Normal file
7
src/base/rules/filenames.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
module.exports = {
|
||||
// === DISABLED ===
|
||||
"filenames/no-index": "off",
|
||||
"filenames/match-exported": "off",
|
||||
// ==== ERRORS ====
|
||||
"filenames/match-regex": ["error", "kebab"],
|
||||
};
|
|
@ -1,18 +1,18 @@
|
|||
module.exports = {
|
||||
// === DISABLED ===
|
||||
// recommended is error, typescript covers this and import/named error has issues
|
||||
'import/named': 'off',
|
||||
"import/named": "off",
|
||||
// on by default, we do NOT want export default ever.
|
||||
'import/default': 'off',
|
||||
"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' }],
|
||||
"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',
|
||||
"import/no-internal-modules": ["error"],
|
||||
"import/no-cycle": "error",
|
||||
"import/no-mutable-exports": "error",
|
||||
"import/no-default-export": "error",
|
||||
};
|
||||
|
|
|
@ -2,5 +2,5 @@ module.exports = {
|
|||
// === DISABLED ===
|
||||
// ==== ERRORS ====
|
||||
// recommended is warn => enforcing error
|
||||
'new-with-error/new-with-error': 'error',
|
||||
"new-with-error/new-with-error": "error",
|
||||
};
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
module.exports = {
|
||||
// === DISABLED ===
|
||||
// ==== ERRORS ====
|
||||
'prettier/prettier': 'error',
|
||||
"prettier/prettier": "error",
|
||||
};
|
||||
|
|
|
@ -1,20 +1,26 @@
|
|||
module.exports = {
|
||||
// === DISABLED ===
|
||||
// We like parameter properties, so turn them on by turning off this default inverse rule.
|
||||
'@typescript-eslint/no-parameter-properties': 'off',
|
||||
"@typescript-eslint/no-parameter-properties": "off",
|
||||
// ==== ERRORS ====
|
||||
// recommended is warn => enforcing error
|
||||
'@typescript-eslint/no-unused-vars': 'error',
|
||||
"@typescript-eslint/no-unused-vars": "error",
|
||||
// recommended is warn => enforcing error
|
||||
'@typescript-eslint/no-explicit-any': 'error',
|
||||
"@typescript-eslint/no-explicit-any": "error",
|
||||
// recommended is warn => enforcing error
|
||||
'@typescript-eslint/explicit-function-return-type': ['error', {
|
||||
allowExpressions: true,
|
||||
allowTypedFunctionExpressions: true
|
||||
}],
|
||||
"@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',
|
||||
"@typescript-eslint/explicit-member-accessibility": [
|
||||
"error",
|
||||
{
|
||||
accessibility: "no-public",
|
||||
},
|
||||
],
|
||||
"@typescript-eslint/no-extraneous-class": "error",
|
||||
};
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
module.exports = {
|
||||
'import/parsers': {
|
||||
'@typescript-eslint/parser': ['.ts', '.tsx']
|
||||
"import/parsers": {
|
||||
"@typescript-eslint/parser": [".ts", ".tsx"],
|
||||
},
|
||||
'import/resolver': {
|
||||
"import/resolver": {
|
||||
typescript: {
|
||||
alwaysTryTypes: false,
|
||||
},
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
module.exports = {
|
||||
base: require('../base'),
|
||||
react: require('../react'),
|
||||
prettierConfig: require('./prettier'),
|
||||
}
|
||||
base: require("../base"),
|
||||
react: require("../react"),
|
||||
prettierConfig: require("./prettier"),
|
||||
};
|
||||
|
|
|
@ -5,8 +5,8 @@ module.exports = {
|
|||
useTabs: false,
|
||||
semi: true,
|
||||
singleQuote: true,
|
||||
trailingComma: 'all',
|
||||
trailingComma: "all",
|
||||
bracketSpacing: true,
|
||||
jsxBracketSameLine: false,
|
||||
arrowParens: 'always',
|
||||
arrowParens: "always",
|
||||
};
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
module.exports = [
|
||||
{
|
||||
files: ['**/*.tsx'],
|
||||
files: ["**/*.tsx", "**/*.jsx"],
|
||||
rules: {
|
||||
// [Plugin] react - disable prop type checks in typescript since we use interfaces
|
||||
'react/prop-types': 'off',
|
||||
"react/prop-types": "off",
|
||||
|
||||
// Allow ts-ignore in test files for easily faking data and objects
|
||||
'@typescript-eslint/ban-ts-ignore': 'off',
|
||||
"@typescript-eslint/ban-ts-ignore": "off",
|
||||
},
|
||||
},
|
||||
];
|
||||
|
|
4
src/react/rules/react-hooks.js
vendored
4
src/react/rules/react-hooks.js
vendored
|
@ -1,6 +1,6 @@
|
|||
module.exports = {
|
||||
// === DISABLED ===
|
||||
// ==== ERRORS ====
|
||||
'react-hooks/rules-of-hooks': 'error',
|
||||
'react-hooks/exhaustive-deps': 'error',
|
||||
"react-hooks/rules-of-hooks": "error",
|
||||
"react-hooks/exhaustive-deps": "error",
|
||||
};
|
||||
|
|
39
src/react/rules/react.js
vendored
39
src/react/rules/react.js
vendored
|
@ -1,23 +1,26 @@
|
|||
module.exports = {
|
||||
// === DISABLED ===
|
||||
// This does not play nice with React.memo()
|
||||
'react/display-name': 'off',
|
||||
"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: 'ignore',
|
||||
}],
|
||||
"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: "ignore",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
|
4
src/react/settings/react.js
vendored
4
src/react/settings/react.js
vendored
|
@ -1,6 +1,6 @@
|
|||
module.exports = {
|
||||
react: {
|
||||
pragma: 'React',
|
||||
version: 'detect',
|
||||
pragma: "React",
|
||||
version: "detect",
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue