-
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
Showing
11 changed files
with
890 additions
and
561 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
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 @@ | ||
# @noahnu/eslint-config | ||
|
||
## Usage | ||
|
||
In your `.eslintrc.js` file: | ||
|
||
```js | ||
module.exports = { | ||
extends: '@noahnu/eslint-config', | ||
parserOptions: { | ||
tsconfigRootDir: __dirname, | ||
project: ['./tsconfig.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,89 @@ | ||
{ | ||
"name": "@noahnu/eslint-config", | ||
"version": "0.0.0", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/noahnu/nodejs-tools.git", | ||
"directory": "packages/eslint-config" | ||
}, | ||
"license": "MIT", | ||
"author": { | ||
"name": "noahnu", | ||
"email": "[email protected]", | ||
"url": "https://noahnu.com" | ||
}, | ||
"scripts": { | ||
"clean": "run workspace:clean \"$(pwd)\"", | ||
"prepack": "run workspace:build \"$(pwd)\"", | ||
"run-local": "run -T ts-node --transpileOnly ./src/bin.ts" | ||
}, | ||
"main": "./src/index.ts", | ||
"exports": { | ||
".": { | ||
"default": "./src/index.ts" | ||
}, | ||
"./base": { | ||
"default": "./src/base/index.ts" | ||
}, | ||
"./jest": { | ||
"default": "./src/jest/index.ts" | ||
} | ||
}, | ||
"publishConfig": { | ||
"registry": "https://registry.npmjs.org/", | ||
"access": "public", | ||
"bin": "./lib/bin.js", | ||
"main": "./lib/index.js", | ||
"types": "./lib/index.d.ts", | ||
"exports": { | ||
".": { | ||
"default": "./lib/index.js" | ||
}, | ||
"./base": { | ||
"default": "./lib/base/index.js" | ||
}, | ||
"./jest": { | ||
"default": "./lib/jest/index.js" | ||
} | ||
} | ||
}, | ||
"files": [ | ||
"lib" | ||
], | ||
"devDependencies": { | ||
"@types/debug": "^4.1.12", | ||
"@types/eslint": "^8.56.6", | ||
"@types/jest": "^29.5.12", | ||
"@types/node": "^18.15.11", | ||
"@typescript-eslint/eslint-plugin": "^7.4.0", | ||
"@typescript-eslint/parser": "^7.4.0", | ||
"@typescript-eslint/utils": "^7.4.0", | ||
"eslint": "^8.57.0", | ||
"eslint-config-prettier": "^9.1.0", | ||
"eslint-import-resolver-node": "^0.3.9", | ||
"eslint-import-resolver-typescript": "^3.6.1", | ||
"eslint-plugin-import": "^2.29.1", | ||
"eslint-plugin-jest": "^27.9.0", | ||
"eslint-plugin-prettier": "^5.1.3", | ||
"prettier": "^3.0.3" | ||
}, | ||
"dependencies": { | ||
"@noahnu/eslint-import-resolver-require": "workspace:*", | ||
"debug": "^4.3.4", | ||
"eslint-import-resolver-typescript": "^3.6.1" | ||
}, | ||
"peerDependencies": { | ||
"@noahnu/eslint-import-resolver-require": "workspace:*", | ||
"@typescript-eslint/eslint-plugin": ">=7.4.0", | ||
"@typescript-eslint/parser": ">=7.4.0", | ||
"eslint": ">=8.57.0", | ||
"eslint-config-prettier": ">=9.1.0", | ||
"eslint-import-resolver-node": ">=0.3.9", | ||
"eslint-import-resolver-typescript": ">=3.6.1", | ||
"eslint-plugin-import": ">=2.29.1", | ||
"eslint-plugin-jest": ">=27.9.0", | ||
"eslint-plugin-prettier": ">=5.1.3", | ||
"prettier": ">=3.2.5", | ||
"typescript": ">=5.4.3" | ||
} | ||
} |
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,181 @@ | ||
import { type ESLint } from 'eslint' | ||
|
||
const rules: ESLint.ConfigData['rules'] = { | ||
/* Prettier Overrides */ | ||
'prettier/prettier': [ | ||
'error', | ||
{ | ||
printWidth: 100, | ||
tabWidth: 4, | ||
semi: false, | ||
trailingComma: 'all' /* Reduces git diff. */, | ||
singleQuote: true, | ||
arrowParens: 'always', // Reduces character diff when adding Typescript types. | ||
}, | ||
], | ||
|
||
/* Variables */ | ||
'no-var': 'error', | ||
'prefer-const': 'error', | ||
'no-unused-vars': 'off', // Prefer equivalent rule from @typescript-eslint */ | ||
'@typescript-eslint/no-unused-vars': [ | ||
'error', | ||
{ | ||
/* By ignoring rest siblings, we support using `...rest` as an alternative to | ||
* a 3rd party omit function, to omit keys from an object. */ | ||
ignoreRestSiblings: true, | ||
// The following allows us to maintain args for type purposes without needing to use them, | ||
// for example, a reducer in which the action is typed but we don't use the action in the | ||
// reducer | ||
argsIgnorePattern: '^_', | ||
// The alternative to this is to use empty array syntax, such as const [, , thing] = someArr | ||
// this syntax lets you at least name the unused parameters which reads a bit nicer, i.e. | ||
// const [_first, _second, third] = someArr | ||
destructuredArrayIgnorePattern: '^_', | ||
}, | ||
], | ||
|
||
/* Strings */ | ||
quotes: ['error', 'single', { avoidEscape: true }], | ||
'prefer-template': 'error', | ||
|
||
/* Naming Convention */ | ||
camelcase: 'off', // disabled in favour of @typescript-eslint's version | ||
'@typescript-eslint/naming-convention': 'off', // to enable this, we require a deeper exploration of our naming patterns | ||
|
||
/* Object Properties */ | ||
'dot-notation': 'error', | ||
'no-useless-computed-key': 'error', | ||
'no-import-assign': 'warn', | ||
|
||
/* Conditionals */ | ||
eqeqeq: 'error', | ||
'no-nested-ternary': 'error', | ||
|
||
/* Behaviours */ | ||
/* | ||
* Rule: Disallow empty function blocks. | ||
* Reason Disabled: Useful for try..catch{} where we don't care about failure. | ||
*/ | ||
'@typescript-eslint/no-empty-function': 'off', | ||
'no-empty': ['error', { allowEmptyCatch: true }], | ||
|
||
/* Broken Rules */ | ||
/* | ||
* Rule: Disallow assignments that can lead to race conditions. | ||
* Reason Disabled: The rule is broken and leads to many false positives. | ||
* See: https://github.com/eslint/eslint/issues/11899 | ||
*/ | ||
'require-atomic-updates': 'off', | ||
|
||
/* Imports */ | ||
'no-duplicate-imports': 'error', | ||
'sort-imports': [ | ||
'error', | ||
{ | ||
/* Prefer import/order declaration sort due to autofixer */ | ||
ignoreDeclarationSort: true, | ||
}, | ||
], | ||
'import/default': 'error', | ||
'import/export': 'error', | ||
'import/named': 'error', | ||
'import/newline-after-import': 'error', | ||
'import/no-absolute-path': 'error', | ||
'import/no-duplicates': 'error', | ||
'import/no-mutable-exports': 'error', | ||
'import/no-self-import': 'error', | ||
'import/no-useless-path-segments': 'error', | ||
'import/no-unresolved': 'error', | ||
'import/order': [ | ||
'error', | ||
{ | ||
alphabetize: { order: 'asc' }, | ||
'newlines-between': 'always', | ||
groups: ['unknown', 'builtin', 'external', 'internal', 'parent', 'sibling', 'index'], | ||
}, | ||
], | ||
|
||
/* Typescript Types */ | ||
'@typescript-eslint/no-non-null-assertion': 'off', | ||
'@typescript-eslint/no-explicit-any': 'off', | ||
'@typescript-eslint/explicit-function-return-type': 'off', | ||
'@typescript-eslint/ban-ts-comment': 'warn', // Discourage disabling static analysis. | ||
'@typescript-eslint/ban-types': 'warn', // Discourage disabling static analysis. | ||
'@typescript-eslint/consistent-type-imports': [ | ||
'error', | ||
{ prefer: 'type-imports', fixStyle: 'inline-type-imports' }, | ||
], | ||
'@typescript-eslint/no-duplicate-enum-values': 'error', | ||
'@typescript-eslint/no-for-in-array': 'error', | ||
'@typescript-eslint/no-non-null-asserted-nullish-coalescing': 'error', | ||
'@typescript-eslint/prefer-includes': 'error', | ||
'@typescript-eslint/prefer-for-of': 'error', | ||
'@typescript-eslint/prefer-optional-chain': 'error', | ||
'@typescript-eslint/prefer-ts-expect-error': 'error', | ||
|
||
// no-use-before-define can cause errors with typescript concepts, like types or enums | ||
'no-use-before-define': 'off', | ||
// functions can be called before they are defined because function declarations are hoisted | ||
'@typescript-eslint/no-use-before-define': ['error', { functions: false }], | ||
} | ||
|
||
const jsIncompatibleRules: ESLint.ConfigData['rules'] = { | ||
/* | ||
* Rule: Disallow require statements in favour of import statements. | ||
* Reason Disabled: We don't know if JS files are transpiled, so don't bother enforcing TS import syntax. | ||
*/ | ||
'@typescript-eslint/no-var-requires': 'off', | ||
} | ||
|
||
const config: ESLint.ConfigData = { | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
ecmaVersion: 'latest', | ||
sourceType: 'module', | ||
}, | ||
plugins: ['import', 'prettier', '@typescript-eslint'], | ||
extends: [ | ||
'eslint:recommended', | ||
'plugin:@typescript-eslint/recommended', | ||
'plugin:@typescript-eslint/stylistic', | ||
// prettier must be the last item in this list to prevent conflicts | ||
'prettier', | ||
], | ||
env: { | ||
node: true, | ||
es2024: true, | ||
}, | ||
rules, | ||
overrides: [ | ||
{ | ||
files: ['**/*.js', '**/*.cjs', '**/*.mjs'], | ||
rules: jsIncompatibleRules, | ||
}, | ||
], | ||
settings: { | ||
'import/external-module-folders': ['node_modules', '.yarn'], | ||
'import/parsers': { | ||
'@typescript-eslint/parser': [ | ||
'.ts', | ||
'.tsx', | ||
'.mts', | ||
'.cts', | ||
'.js', | ||
'.mjs', | ||
'.cjs', | ||
'.jsx', | ||
], | ||
}, | ||
'import/resolver': [ | ||
{ | ||
[require.resolve('eslint-import-resolver-typescript')]: { | ||
alwaysTryTypes: true, | ||
}, | ||
}, | ||
{ [require.resolve('@noahnu/eslint-import-resolver-require')]: {} }, | ||
], | ||
}, | ||
} | ||
|
||
export = config |
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,14 @@ | ||
import { type ESLint } from 'eslint' | ||
|
||
const config: ESLint.ConfigData = { | ||
extends: ['@noahnu/eslint-config/base'], | ||
rules: {}, | ||
overrides: [ | ||
{ | ||
files: ['**/*.test.*'], | ||
extends: ['@noahnu/eslint-config/jest'], | ||
}, | ||
], | ||
} | ||
|
||
export = config |
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,12 @@ | ||
import { type ESLint } from 'eslint' | ||
|
||
const config: ESLint.ConfigData = { | ||
env: { | ||
jest: true, | ||
}, | ||
plugins: ['jest'], | ||
extends: ['plugin:jest/recommended', 'plugin:jest/style'], | ||
rules: {}, | ||
} | ||
|
||
export = config |
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 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"rootDir": "./src", | ||
"tsBuildInfoFile": "./.tmp/.tsbuildinfo", | ||
}, | ||
"include": ["./src"], | ||
"exclude": ["./src/**/*.test.ts"] | ||
} |
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,8 @@ | ||
{ | ||
"extends": "../tsconfig.json", | ||
"compilerOptions": { | ||
"declarationDir": "./lib", | ||
"outDir": "./lib" | ||
}, | ||
"include": ["./src"], | ||
} |
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
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
Oops, something went wrong.