Skip to content

Commit da55da8

Browse files
authored
Initial release of @noahnu/eslint-config (#4)
* feat: new eslint-config package * chore: release
1 parent 4c2df9b commit da55da8

File tree

12 files changed

+894
-561
lines changed

12 files changed

+894
-561
lines changed

.monoweave/12e3cdf5.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
"@noahnu/eslint-config": major
3+
---
4+
Initial release of eslint-config.

package.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,21 @@
3030
"@tophat/jest-resolver": "^0.1.0",
3131
"@types/jest": "^29.5.8",
3232
"@types/node": "^20",
33-
"@typescript-eslint/eslint-plugin": "^6.18.1",
34-
"@typescript-eslint/parser": "^6.18.1",
33+
"@typescript-eslint/eslint-plugin": "^7.4.0",
34+
"@typescript-eslint/parser": "^7.4.0",
3535
"@yarnpkg/core": "^4.0.3",
3636
"@yarnpkg/sdks": "^3.1.0",
3737
"@yarnpkg/types": "^4.0.0",
3838
"commitizen": "^4.3.0",
39-
"eslint": "^8.53.0",
40-
"eslint-config-prettier": "^9.0.0",
39+
"eslint": "^8.57.0",
40+
"eslint-config-prettier": "^9.1.0",
4141
"eslint-import-resolver-node": "^0.3.9",
4242
"eslint-import-resolver-typescript": "^3.6.1",
43-
"eslint-plugin-import": "^2.29.0",
44-
"eslint-plugin-jest": "^27.6.0",
43+
"eslint-plugin-import": "^2.29.1",
44+
"eslint-plugin-jest": "^27.9.0",
4545
"eslint-plugin-jsx-a11y": "^6.8.0",
46-
"eslint-plugin-prettier": "^5.0.1",
47-
"eslint-plugin-react": "^7.33.2",
46+
"eslint-plugin-prettier": "^5.1.3",
47+
"eslint-plugin-react": "^7.34.1",
4848
"eslint-plugin-react-hooks": "^4.6.0",
4949
"husky": "^8.0.3",
5050
"jest": "^29.7.0",

packages/eslint-config/README.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# @noahnu/eslint-config
2+
3+
## Usage
4+
5+
In your `.eslintrc.js` file:
6+
7+
```js
8+
module.exports = {
9+
extends: '@noahnu/eslint-config',
10+
parserOptions: {
11+
tsconfigRootDir: __dirname,
12+
project: ['./tsconfig.json'],
13+
},
14+
};
15+
```

packages/eslint-config/package.json

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
{
2+
"name": "@noahnu/eslint-config",
3+
"version": "0.0.0",
4+
"repository": {
5+
"type": "git",
6+
"url": "https://github.com/noahnu/nodejs-tools.git",
7+
"directory": "packages/eslint-config"
8+
},
9+
"license": "MIT",
10+
"author": {
11+
"name": "noahnu",
12+
"email": "[email protected]",
13+
"url": "https://noahnu.com"
14+
},
15+
"scripts": {
16+
"clean": "run workspace:clean \"$(pwd)\"",
17+
"prepack": "run workspace:build \"$(pwd)\"",
18+
"run-local": "run -T ts-node --transpileOnly ./src/bin.ts"
19+
},
20+
"main": "./src/index.ts",
21+
"exports": {
22+
".": {
23+
"default": "./src/index.ts"
24+
},
25+
"./base": {
26+
"default": "./src/base/index.ts"
27+
},
28+
"./jest": {
29+
"default": "./src/jest/index.ts"
30+
}
31+
},
32+
"publishConfig": {
33+
"registry": "https://registry.npmjs.org/",
34+
"access": "public",
35+
"bin": "./lib/bin.js",
36+
"main": "./lib/index.js",
37+
"types": "./lib/index.d.ts",
38+
"exports": {
39+
".": {
40+
"default": "./lib/index.js"
41+
},
42+
"./base": {
43+
"default": "./lib/base/index.js"
44+
},
45+
"./jest": {
46+
"default": "./lib/jest/index.js"
47+
}
48+
}
49+
},
50+
"files": [
51+
"lib"
52+
],
53+
"devDependencies": {
54+
"@types/debug": "^4.1.12",
55+
"@types/eslint": "^8.56.6",
56+
"@types/jest": "^29.5.12",
57+
"@types/node": "^18.15.11",
58+
"@typescript-eslint/eslint-plugin": "^7.4.0",
59+
"@typescript-eslint/parser": "^7.4.0",
60+
"@typescript-eslint/utils": "^7.4.0",
61+
"eslint": "^8.57.0",
62+
"eslint-config-prettier": "^9.1.0",
63+
"eslint-import-resolver-node": "^0.3.9",
64+
"eslint-import-resolver-typescript": "^3.6.1",
65+
"eslint-plugin-import": "^2.29.1",
66+
"eslint-plugin-jest": "^27.9.0",
67+
"eslint-plugin-prettier": "^5.1.3",
68+
"prettier": "^3.0.3"
69+
},
70+
"dependencies": {
71+
"@noahnu/eslint-import-resolver-require": "workspace:*",
72+
"debug": "^4.3.4",
73+
"eslint-import-resolver-typescript": "^3.6.1"
74+
},
75+
"peerDependencies": {
76+
"@noahnu/eslint-import-resolver-require": "workspace:*",
77+
"@typescript-eslint/eslint-plugin": ">=7.4.0",
78+
"@typescript-eslint/parser": ">=7.4.0",
79+
"eslint": ">=8.57.0",
80+
"eslint-config-prettier": ">=9.1.0",
81+
"eslint-import-resolver-node": ">=0.3.9",
82+
"eslint-import-resolver-typescript": ">=3.6.1",
83+
"eslint-plugin-import": ">=2.29.1",
84+
"eslint-plugin-jest": ">=27.9.0",
85+
"eslint-plugin-prettier": ">=5.1.3",
86+
"prettier": ">=3.2.5",
87+
"typescript": ">=5.4.3"
88+
}
89+
}
+181
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
import { type ESLint } from 'eslint'
2+
3+
const rules: ESLint.ConfigData['rules'] = {
4+
/* Prettier Overrides */
5+
'prettier/prettier': [
6+
'error',
7+
{
8+
printWidth: 100,
9+
tabWidth: 4,
10+
semi: false,
11+
trailingComma: 'all' /* Reduces git diff. */,
12+
singleQuote: true,
13+
arrowParens: 'always', // Reduces character diff when adding Typescript types.
14+
},
15+
],
16+
17+
/* Variables */
18+
'no-var': 'error',
19+
'prefer-const': 'error',
20+
'no-unused-vars': 'off', // Prefer equivalent rule from @typescript-eslint */
21+
'@typescript-eslint/no-unused-vars': [
22+
'error',
23+
{
24+
/* By ignoring rest siblings, we support using `...rest` as an alternative to
25+
* a 3rd party omit function, to omit keys from an object. */
26+
ignoreRestSiblings: true,
27+
// The following allows us to maintain args for type purposes without needing to use them,
28+
// for example, a reducer in which the action is typed but we don't use the action in the
29+
// reducer
30+
argsIgnorePattern: '^_',
31+
// The alternative to this is to use empty array syntax, such as const [, , thing] = someArr
32+
// this syntax lets you at least name the unused parameters which reads a bit nicer, i.e.
33+
// const [_first, _second, third] = someArr
34+
destructuredArrayIgnorePattern: '^_',
35+
},
36+
],
37+
38+
/* Strings */
39+
quotes: ['error', 'single', { avoidEscape: true }],
40+
'prefer-template': 'error',
41+
42+
/* Naming Convention */
43+
camelcase: 'off', // disabled in favour of @typescript-eslint's version
44+
'@typescript-eslint/naming-convention': 'off', // to enable this, we require a deeper exploration of our naming patterns
45+
46+
/* Object Properties */
47+
'dot-notation': 'error',
48+
'no-useless-computed-key': 'error',
49+
'no-import-assign': 'warn',
50+
51+
/* Conditionals */
52+
eqeqeq: 'error',
53+
'no-nested-ternary': 'error',
54+
55+
/* Behaviours */
56+
/*
57+
* Rule: Disallow empty function blocks.
58+
* Reason Disabled: Useful for try..catch{} where we don't care about failure.
59+
*/
60+
'@typescript-eslint/no-empty-function': 'off',
61+
'no-empty': ['error', { allowEmptyCatch: true }],
62+
63+
/* Broken Rules */
64+
/*
65+
* Rule: Disallow assignments that can lead to race conditions.
66+
* Reason Disabled: The rule is broken and leads to many false positives.
67+
* See: https://github.com/eslint/eslint/issues/11899
68+
*/
69+
'require-atomic-updates': 'off',
70+
71+
/* Imports */
72+
'no-duplicate-imports': 'error',
73+
'sort-imports': [
74+
'error',
75+
{
76+
/* Prefer import/order declaration sort due to autofixer */
77+
ignoreDeclarationSort: true,
78+
},
79+
],
80+
'import/default': 'error',
81+
'import/export': 'error',
82+
'import/named': 'error',
83+
'import/newline-after-import': 'error',
84+
'import/no-absolute-path': 'error',
85+
'import/no-duplicates': 'error',
86+
'import/no-mutable-exports': 'error',
87+
'import/no-self-import': 'error',
88+
'import/no-useless-path-segments': 'error',
89+
'import/no-unresolved': 'error',
90+
'import/order': [
91+
'error',
92+
{
93+
alphabetize: { order: 'asc' },
94+
'newlines-between': 'always',
95+
groups: ['unknown', 'builtin', 'external', 'internal', 'parent', 'sibling', 'index'],
96+
},
97+
],
98+
99+
/* Typescript Types */
100+
'@typescript-eslint/no-non-null-assertion': 'off',
101+
'@typescript-eslint/no-explicit-any': 'off',
102+
'@typescript-eslint/explicit-function-return-type': 'off',
103+
'@typescript-eslint/ban-ts-comment': 'warn', // Discourage disabling static analysis.
104+
'@typescript-eslint/ban-types': 'warn', // Discourage disabling static analysis.
105+
'@typescript-eslint/consistent-type-imports': [
106+
'error',
107+
{ prefer: 'type-imports', fixStyle: 'inline-type-imports' },
108+
],
109+
'@typescript-eslint/no-duplicate-enum-values': 'error',
110+
'@typescript-eslint/no-for-in-array': 'error',
111+
'@typescript-eslint/no-non-null-asserted-nullish-coalescing': 'error',
112+
'@typescript-eslint/prefer-includes': 'error',
113+
'@typescript-eslint/prefer-for-of': 'error',
114+
'@typescript-eslint/prefer-optional-chain': 'error',
115+
'@typescript-eslint/prefer-ts-expect-error': 'error',
116+
117+
// no-use-before-define can cause errors with typescript concepts, like types or enums
118+
'no-use-before-define': 'off',
119+
// functions can be called before they are defined because function declarations are hoisted
120+
'@typescript-eslint/no-use-before-define': ['error', { functions: false }],
121+
}
122+
123+
const jsIncompatibleRules: ESLint.ConfigData['rules'] = {
124+
/*
125+
* Rule: Disallow require statements in favour of import statements.
126+
* Reason Disabled: We don't know if JS files are transpiled, so don't bother enforcing TS import syntax.
127+
*/
128+
'@typescript-eslint/no-var-requires': 'off',
129+
}
130+
131+
const config: ESLint.ConfigData = {
132+
parser: '@typescript-eslint/parser',
133+
parserOptions: {
134+
ecmaVersion: 'latest',
135+
sourceType: 'module',
136+
},
137+
plugins: ['import', 'prettier', '@typescript-eslint'],
138+
extends: [
139+
'eslint:recommended',
140+
'plugin:@typescript-eslint/recommended',
141+
'plugin:@typescript-eslint/stylistic',
142+
// prettier must be the last item in this list to prevent conflicts
143+
'prettier',
144+
],
145+
env: {
146+
node: true,
147+
es2024: true,
148+
},
149+
rules,
150+
overrides: [
151+
{
152+
files: ['**/*.js', '**/*.cjs', '**/*.mjs'],
153+
rules: jsIncompatibleRules,
154+
},
155+
],
156+
settings: {
157+
'import/external-module-folders': ['node_modules', '.yarn'],
158+
'import/parsers': {
159+
'@typescript-eslint/parser': [
160+
'.ts',
161+
'.tsx',
162+
'.mts',
163+
'.cts',
164+
'.js',
165+
'.mjs',
166+
'.cjs',
167+
'.jsx',
168+
],
169+
},
170+
'import/resolver': [
171+
{
172+
[require.resolve('eslint-import-resolver-typescript')]: {
173+
alwaysTryTypes: true,
174+
},
175+
},
176+
{ [require.resolve('@noahnu/eslint-import-resolver-require')]: {} },
177+
],
178+
},
179+
}
180+
181+
export = config

packages/eslint-config/src/index.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { type ESLint } from 'eslint'
2+
3+
const config: ESLint.ConfigData = {
4+
extends: ['@noahnu/eslint-config/base'],
5+
rules: {},
6+
overrides: [
7+
{
8+
files: ['**/*.test.*'],
9+
extends: ['@noahnu/eslint-config/jest'],
10+
},
11+
],
12+
}
13+
14+
export = config
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { type ESLint } from 'eslint'
2+
3+
const config: ESLint.ConfigData = {
4+
env: {
5+
jest: true,
6+
},
7+
plugins: ['jest'],
8+
extends: ['plugin:jest/recommended', 'plugin:jest/style'],
9+
rules: {},
10+
}
11+
12+
export = config
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"rootDir": "./src",
5+
"tsBuildInfoFile": "./.tmp/.tsbuildinfo",
6+
},
7+
"include": ["./src"],
8+
"exclude": ["./src/**/*.test.ts"]
9+
}

packages/eslint-config/tsconfig.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"compilerOptions": {
4+
"declarationDir": "./lib",
5+
"outDir": "./lib"
6+
},
7+
"include": ["./src"],
8+
}

packages/eslint-import-resolver-require/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"@types/eslint": "^8.44.3",
3434
"@types/jest": "^29.5.5",
3535
"@types/node": "^18.15.11",
36-
"eslint": "^8.50.0",
36+
"eslint": "^8.57.0",
3737
"eslint-plugin-import": "^2.29.1"
3838
},
3939
"dependencies": {

packages/unused-files/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
],
3232
"dependencies": {
3333
"@types/debug": "^4.1.12",
34-
"@typescript-eslint/typescript-estree": "^6.18.1",
34+
"@typescript-eslint/typescript-estree": "^7.4.0",
3535
"clipanion": "4.0.0-rc.2",
3636
"debug": "^4.3.4",
3737
"fast-glob": "^3.3.2",

0 commit comments

Comments
 (0)