update to latests

This commit is contained in:
RingOfStorms (Joshua Bell) 2023-01-10 00:37:47 -06:00
parent 71c67f66de
commit af0c093759
19 changed files with 2194 additions and 1018 deletions

View file

@ -1,6 +1,7 @@
# Eslint Config # Eslint Config
# Notable linting rules # Notable linting rules
- No default exports - No default exports
- No relative imports from other modules, imports must be exported in an index file - No relative imports from other modules, imports must be exported in an index file
- Index files only contain imports/exports, no other code - 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 \ npm i @ringofstorms/eslint-config \
@typescript-eslint/eslint-plugin \ @typescript-eslint/eslint-plugin \
@typescript-eslint/parser \
eslint \ eslint \
eslint-config-prettier \
eslint-import-resolver-typescript \
eslint-plugin-eslint-comments \ eslint-plugin-eslint-comments \
eslint-plugin-filenames \
eslint-plugin-import \ eslint-plugin-import \
eslint-plugin-new-with-error \ eslint-plugin-new-with-error \
eslint-plugin-prettier \ eslint-plugin-prettier \
@typescript-eslint/parser \
eslint-config-prettier \
eslint-config-react \
eslint-import-resolver-typescript \
prettier \ prettier \
--save-dev --save-dev
``` ```
In your .eslintrc In your .eslintrc
``` ```
{ {
extends: ["@ringofstorms/eslint-config/base"], extends: ["@ringofstorms/eslint-config/base"],
@ -35,28 +37,31 @@ In your .eslintrc
``` ```
## react ## react
React is for react/typescript and is base + react specific settings. React is for react/typescript and is base + react specific settings.
``` ```
npm i @ringofstorms/eslint-config \ npm i @ringofstorms/eslint-config \
@typescript-eslint/eslint-plugin \ @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 \ @typescript-eslint/parser \
eslint \
eslint-config-prettier \ eslint-config-prettier \
eslint-config-react \ eslint-config-react \
eslint-import-resolver-typescript \ 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 --save-dev
``` ```
In your .eslintrc In your .eslintrc
``` ```
{ {
extends: ["@ringofstorms/eslint-config/react"], extends: ["@ringofstorms/eslint-config/react"],
@ -66,6 +71,7 @@ In your .eslintrc
## prettier settings ## prettier settings
Create `prettier.config.js` file in root of project with this content: Create `prettier.config.js` file in root of project with this content:
``` ```
module.exports = require('@ringofstorms/eslint-config').prettierConfig; module.exports = require('@ringofstorms/eslint-config').prettierConfig;
``` ```
@ -86,9 +92,11 @@ module.exports = require('@ringofstorms/eslint-config').prettierConfig;
# Contributing # Contributing
## Packing ## Packing
`npm pack` `npm pack`
## publishing ## publishing
if not already done `npm login` if not already done `npm login`
`npm publish --access public` `npm publish --access public`

47
base.js
View file

@ -1,19 +1,20 @@
module.exports = { module.exports = {
parser: '@typescript-eslint/parser', parser: "@typescript-eslint/parser",
plugins: [ plugins: [
'@typescript-eslint', "@typescript-eslint",
'prettier', "eslint-comments",
'import', "filenames",
'eslint-comments', "import",
'new-with-error', "new-with-error",
"prettier",
], ],
extends: [ extends: [
'eslint:recommended', "eslint:recommended",
'plugin:@typescript-eslint/recommended', "plugin:@typescript-eslint/recommended",
'plugin:import/errors', "plugin:eslint-comments/recommended",
'plugin:import/typescript', "plugin:import/errors",
'plugin:eslint-comments/recommended', "plugin:import/typescript",
'prettier', "prettier",
], ],
env: { env: {
node: true, node: true,
@ -24,21 +25,15 @@ module.exports = {
process: true, process: true,
}, },
settings: { settings: {
...require('./src/base/settings/import'), ...require("./src/base/settings/import"),
}, },
rules: { rules: {
...require('./src/base/rules/eslint'), ...require("./src/base/rules/eslint"),
...require('./src/base/rules/import'), ...require("./src/base/rules/filenames"),
...require('./src/base/rules/new-with-error'), ...require("./src/base/rules/import"),
...require('./src/base/rules/prettier'), ...require("./src/base/rules/new-with-error"),
...require('./src/base/rules/typescript-eslint'), ...require("./src/base/rules/prettier"),
...require("./src/base/rules/typescript-eslint"),
}, },
overrides: [ overrides: [...require("./src/base/overrides")],
{
files: "prettier.config.js",
rules: {
"@typescript-eslint/no-var-requires": "off"
}
}
]
}; };

2906
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
{ {
"name": "@ringofstorms/eslint-config", "name": "@ringofstorms/eslint-config",
"version": "0.2.0", "version": "0.3.0",
"description": "Opinionated eslint configuration for node typescript projects", "description": "Opinionated eslint configuration for node typescript projects",
"main": "src/index.js", "main": "src/index.js",
"files": [ "files": [
@ -11,37 +11,42 @@
], ],
"author": "Josh (RingOfStorms)", "author": "Josh (RingOfStorms)",
"license": "ISC", "license": "ISC",
"scripts": {
"lint:fix": "prettier . --check --write"
},
"peerDependencies": { "peerDependencies": {
"@typescript-eslint/parser": ">= 4", "@typescript-eslint/eslint-plugin": ">=5",
"@typescript-eslint/parser": ">=4",
"eslint": ">=7",
"eslint-config-prettier": ">=8", "eslint-config-prettier": ">=8",
"eslint-config-react": ">= 1", "eslint-config-react": ">= 1",
"eslint-import-resolver-typescript": ">= 2", "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-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": ">= 7",
"eslint-plugin-react-hooks": ">=4" "eslint-plugin-react-hooks": ">=4",
"prettier": ">= 2"
}, },
"devDependencies": { "devDependencies": {
"@typescript-eslint/parser": ">= 4", "@typescript-eslint/eslint-plugin": ">=5",
"@typescript-eslint/parser": ">=4",
"eslint": ">=7",
"eslint-config-prettier": ">=8", "eslint-config-prettier": ">=8",
"eslint-config-react": ">= 1", "eslint-config-react": ">= 1",
"eslint-import-resolver-typescript": ">= 2", "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-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": ">= 7",
"eslint-plugin-react-hooks": ">=4" "eslint-plugin-react-hooks": ">=4",
"prettier": ">= 2"
}, },
"repository": { "repository": {
"type": "git", "type": "git",

28
react.js vendored
View file

@ -1,15 +1,11 @@
module.exports = { module.exports = {
plugins: [ plugins: ["react", "css-modules", "react-hooks"],
'react',
'css-modules',
'react-hooks',
],
extends: [ extends: [
'@ringofstorms/eslint-config/base', "@ringofstorms/eslint-config/base",
'plugin:react/recommended', "plugin:react/recommended",
'plugin:import/react', "plugin:import/react",
'plugin:css-modules/recommended', "plugin:css-modules/recommended",
'prettier', "prettier",
], ],
env: { env: {
browser: true, browser: true,
@ -21,13 +17,11 @@ module.exports = {
process: true, process: true,
}, },
settings: { settings: {
...require('./src/react/settings/react'), ...require("./src/react/settings/react"),
}, },
overrides: [
...require('./src/react/overrides'),
],
rules: { rules: {
...require('./src/react/rules/react'), ...require("./src/react/rules/react"),
...require('./src/react/rules/react-hooks'), ...require("./src/react/rules/react-hooks"),
}, },
} overrides: [...require("./src/react/overrides")],
};

16
src/base/overrides.js Normal file
View 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",
},
},
];

View file

@ -1,8 +1,12 @@
module.exports = { module.exports = {
// === DISABLED === // === DISABLED ===
// ==== ERRORS ==== // ==== ERRORS ====
curly: 'error', curly: "error",
'sort-imports': ['error', { "sort-imports": [
ignoreDeclarationSort: true "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
}; };

View file

@ -0,0 +1,7 @@
module.exports = {
// === DISABLED ===
"filenames/no-index": "off",
"filenames/match-exported": "off",
// ==== ERRORS ====
"filenames/match-regex": ["error", "kebab"],
};

View file

@ -1,18 +1,18 @@
module.exports = { module.exports = {
// === DISABLED === // === DISABLED ===
// recommended is error, typescript covers this and import/named error has issues // 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. // on by default, we do NOT want export default ever.
'import/default': 'off', "import/default": "off",
// ==== ERRORS ==== // ==== ERRORS ====
// We will not use plugin:import/warnings because we want errors // We will not use plugin:import/warnings because we want errors
'import/no-duplicates': 'error', "import/no-duplicates": "error",
'import/order': ['error', { 'newlines-between': 'always' }], "import/order": ["error", { "newlines-between": "always" }],
// This will differ for every project and may not even need any settings // This will differ for every project and may not even need any settings
// COPY this to rules of project: // COPY this to rules of project:
// `"import/no-internal-modules": ["error", { allow: ["uuid/**", "@nestjs/**"] }],` // `"import/no-internal-modules": ["error", { allow: ["uuid/**", "@nestjs/**"] }],`
'import/no-internal-modules': ['error'], "import/no-internal-modules": ["error"],
'import/no-cycle': 'error', "import/no-cycle": "error",
'import/no-mutable-exports': 'error', "import/no-mutable-exports": "error",
'import/no-default-export': 'error', "import/no-default-export": "error",
}; };

View file

@ -2,5 +2,5 @@ module.exports = {
// === DISABLED === // === DISABLED ===
// ==== ERRORS ==== // ==== ERRORS ====
// recommended is warn => enforcing error // recommended is warn => enforcing error
'new-with-error/new-with-error': 'error', "new-with-error/new-with-error": "error",
}; };

View file

@ -1,5 +1,5 @@
module.exports = { module.exports = {
// === DISABLED === // === DISABLED ===
// ==== ERRORS ==== // ==== ERRORS ====
'prettier/prettier': 'error', "prettier/prettier": "error",
}; };

View file

@ -1,20 +1,26 @@
module.exports = { module.exports = {
// === DISABLED === // === DISABLED ===
// We like parameter properties, so turn them on by turning off this default inverse rule. // 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 ==== // ==== ERRORS ====
// recommended is warn => enforcing error // recommended is warn => enforcing error
'@typescript-eslint/no-unused-vars': 'error', "@typescript-eslint/no-unused-vars": "error",
// recommended is warn => enforcing error // recommended is warn => enforcing error
'@typescript-eslint/no-explicit-any': 'error', "@typescript-eslint/no-explicit-any": "error",
// recommended is warn => enforcing error // recommended is warn => enforcing error
'@typescript-eslint/explicit-function-return-type': ['error', { "@typescript-eslint/explicit-function-return-type": [
allowExpressions: true, "error",
allowTypedFunctionExpressions: true {
}], allowExpressions: true,
allowTypedFunctionExpressions: true,
},
],
// recommended does not configure no-public // recommended does not configure no-public
'@typescript-eslint/explicit-member-accessibility': ['error', { "@typescript-eslint/explicit-member-accessibility": [
accessibility: 'no-public', "error",
}], {
'@typescript-eslint/no-extraneous-class': 'error', accessibility: "no-public",
},
],
"@typescript-eslint/no-extraneous-class": "error",
}; };

View file

@ -1,8 +1,8 @@
module.exports = { module.exports = {
'import/parsers': { "import/parsers": {
'@typescript-eslint/parser': ['.ts', '.tsx'] "@typescript-eslint/parser": [".ts", ".tsx"],
}, },
'import/resolver': { "import/resolver": {
typescript: { typescript: {
alwaysTryTypes: false, alwaysTryTypes: false,
}, },

View file

@ -1,5 +1,5 @@
module.exports = { module.exports = {
base: require('../base'), base: require("../base"),
react: require('../react'), react: require("../react"),
prettierConfig: require('./prettier'), prettierConfig: require("./prettier"),
} };

View file

@ -5,8 +5,8 @@ module.exports = {
useTabs: false, useTabs: false,
semi: true, semi: true,
singleQuote: true, singleQuote: true,
trailingComma: 'all', trailingComma: "all",
bracketSpacing: true, bracketSpacing: true,
jsxBracketSameLine: false, jsxBracketSameLine: false,
arrowParens: 'always', arrowParens: "always",
}; };

View file

@ -1,12 +1,12 @@
module.exports = [ module.exports = [
{ {
files: ['**/*.tsx'], files: ["**/*.tsx", "**/*.jsx"],
rules: { rules: {
// [Plugin] react - disable prop type checks in typescript since we use interfaces // [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 // Allow ts-ignore in test files for easily faking data and objects
'@typescript-eslint/ban-ts-ignore': 'off', "@typescript-eslint/ban-ts-ignore": "off",
}, },
}, },
]; ];

View file

@ -1,6 +1,6 @@
module.exports = { module.exports = {
// === DISABLED === // === DISABLED ===
// ==== ERRORS ==== // ==== ERRORS ====
'react-hooks/rules-of-hooks': 'error', "react-hooks/rules-of-hooks": "error",
'react-hooks/exhaustive-deps': 'error', "react-hooks/exhaustive-deps": "error",
}; };

View file

@ -1,23 +1,26 @@
module.exports = { module.exports = {
// === DISABLED === // === DISABLED ===
// This does not play nice with React.memo() // This does not play nice with React.memo()
'react/display-name': 'off', "react/display-name": "off",
// ==== ERRORS ==== // ==== ERRORS ====
'react/no-access-state-in-setstate': 'error', "react/no-access-state-in-setstate": "error",
'react/no-redundant-should-component-update': 'error', "react/no-redundant-should-component-update": "error",
'react/no-typos': 'error', "react/no-typos": "error",
'react/no-unsafe': 'error', "react/no-unsafe": "error",
'react/self-closing-comp': 'error', "react/self-closing-comp": "error",
'react/jsx-no-bind': 'error', "react/jsx-no-bind": "error",
'react/jsx-max-depth': ['error', { max: 5 }], "react/jsx-max-depth": ["error", { max: 5 }],
'react/jsx-curly-brace-presence': ['error', 'never'], "react/jsx-curly-brace-presence": ["error", "never"],
'react/jsx-wrap-multilines': ['error', { "react/jsx-wrap-multilines": [
declaration: 'parens-new-line', "error",
assignment: 'parens-new-line', {
return: 'parens-new-line', declaration: "parens-new-line",
arrow: 'parens-new-line', assignment: "parens-new-line",
condition: 'parens-new-line', return: "parens-new-line",
logical: 'parens-new-line', arrow: "parens-new-line",
prop: 'ignore', condition: "parens-new-line",
}], logical: "parens-new-line",
prop: "ignore",
},
],
}; };

View file

@ -1,6 +1,6 @@
module.exports = { module.exports = {
react: { react: {
pragma: 'React', pragma: "React",
version: 'detect', version: "detect",
}, },
}; };