@thermarthae/eslint-config 0.0.0-experimental.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 thermarthae
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # @thermarthae/eslint-config
2
+
3
+ Just an Eslint config.
4
+
5
+ ## ✨ Setup
6
+
7
+ ### 1) Install
8
+
9
+ This step assumes that you have already installed Eslint and Typescript.
10
+
11
+ ```bash
12
+ yarn add -D @thermarthae/eslint-config @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint-plugin-import@npm:eslint-plugin-i@latest eslint-plugin-jsx-a11y eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-simple-import-sort @stylistic/eslint-plugin
13
+ ```
14
+
15
+ If you don't need React support:
16
+
17
+ ```bash
18
+ yarn add -D @thermarthae/eslint-config @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint-plugin-import@npm:eslint-plugin-i@latest eslint-plugin-simple-import-sort @stylistic/eslint-plugin
19
+ ```
20
+
21
+ ### 2) Configure ESLint
22
+
23
+ Add `"extends": "@thermarthae/eslint-config"` to your ESLint config file.
24
+
25
+ An example `.eslintrc.cjs`:
26
+
27
+ ```js
28
+ module.exports = {
29
+ // If you don't need React support:
30
+ // extends: ['@thermarthae/eslint-config/base.cjs'],
31
+ extends: ['@thermarthae/eslint-config'],
32
+ };
33
+ ```
34
+
35
+ **Note**: If your `tsconfig.json` is not in the same directory as `package.json`, you will have to set the path yourself:
36
+
37
+ ```diff
38
+ module.exports = {
39
+ extends: ['@thermarthae/eslint-config'],
40
+ + parserOptions: {
41
+ + project: './foo/bar/tsconfig.json',
42
+ + },
43
+ };
44
+ ```
package/base.js ADDED
@@ -0,0 +1,6 @@
1
+ import shared from './shared.js';
2
+
3
+ /** @type {typeof import('typescript-eslint').configs.all} */
4
+ export default [
5
+ ...shared,
6
+ ];
package/index.js ADDED
@@ -0,0 +1,89 @@
1
+ import react from 'eslint-plugin-react';
2
+ // @ts-expect-error no types :/
3
+ import reactHooks from 'eslint-plugin-react-hooks';
4
+ import stylistic from '@stylistic/eslint-plugin';
5
+ import jsxA11y from 'eslint-plugin-jsx-a11y';
6
+
7
+ import shared from './shared.js';
8
+
9
+ const stylisticCustomizedWithJSX = stylistic.configs.customize({
10
+ flat: true,
11
+ indent: 'tab',
12
+ semi: true,
13
+ jsx: true,
14
+ braceStyle: '1tbs',
15
+ quoteProps: 'as-needed',
16
+ });
17
+
18
+ const jsxStylisticRules = Object.fromEntries(Object.entries(stylisticCustomizedWithJSX.rules ?? {})
19
+ .filter(r => r[0].startsWith('@stylistic/jsx')));
20
+
21
+ /** @type {typeof import('typescript-eslint').configs.all} */
22
+ const main = [
23
+ ...shared,
24
+ //
25
+ // react
26
+ //
27
+ // react.configs.flat.recommended,
28
+ // react.configs.flat['jsx-runtime'],
29
+ // TODO: wait for a types fix
30
+ /** @type {typeof import('typescript-eslint').configs.base} */ (react.configs.flat.recommended),
31
+ /** @type {typeof import('typescript-eslint').configs.base} */ (react.configs.flat['jsx-runtime']),
32
+ {
33
+ settings: {
34
+ react: {
35
+ version: 'detect',
36
+ },
37
+ },
38
+ rules: {
39
+ 'react/react-in-jsx-scope': 0,
40
+ 'react/no-unknown-property': 0,
41
+ 'react/no-children-prop': 0,
42
+ 'react/prop-types': 0,
43
+ 'react/jsx-boolean-value': ['error', 'never', { always: [] }],
44
+ 'react/void-dom-elements-no-children': 'error',
45
+ 'react/button-has-type': ['error', {
46
+ button: true,
47
+ submit: true,
48
+ reset: false,
49
+ }],
50
+ 'react/jsx-no-useless-fragment': 'error',
51
+ 'react/jsx-no-constructed-context-values': 'error',
52
+ 'react/no-unstable-nested-components': 'error',
53
+ },
54
+ },
55
+ //
56
+ // react-hooks
57
+ //
58
+ // TODO: wait for a native flat support
59
+ {
60
+ files: ['**/**/*.{js,ts,jsx,tsx}'],
61
+ plugins: {
62
+ 'react-hooks': reactHooks,
63
+ },
64
+ rules: reactHooks.configs.recommended.rules,
65
+ },
66
+ //
67
+ // jsx-a11y
68
+ //
69
+ jsxA11y.flatConfigs.recommended,
70
+ //
71
+ // stylistic
72
+ //
73
+ {
74
+ rules: {
75
+ ...jsxStylisticRules,
76
+ '@stylistic/jsx-closing-bracket-location': ['error', 'line-aligned'],
77
+ '@stylistic/jsx-curly-brace-presence': ['error', {
78
+ props: 'never',
79
+ children: 'never',
80
+ propElementValues: 'always',
81
+ }],
82
+ '@stylistic/jsx-curly-spacing': ['error', 'never', { allowMultiline: true }],
83
+ '@stylistic/jsx-self-closing-comp': 'error',
84
+ '@stylistic/jsx-props-no-multi-spaces': 'error',
85
+ },
86
+ },
87
+ ];
88
+
89
+ export default main;
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@thermarthae/eslint-config",
3
+ "version": "0.0.0-experimental.1",
4
+ "main": "index.js",
5
+ "description": "Just a personal eslint config",
6
+ "type": "module",
7
+ "license": "MIT",
8
+ "author": "thermarthae <thermarthae@protonmail.com>",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/thermarthae/eslint-config.git"
12
+ },
13
+ "files": [
14
+ "base.js",
15
+ "index.js",
16
+ "shared.js"
17
+ ],
18
+ "packageManager": "yarn@4.5.1+sha512.341db9396b6e289fecc30cd7ab3af65060e05ebff4b3b47547b278b9e67b08f485ecd8c79006b405446262142c7a38154445ef7f17c1d5d1de7d90bf9ce7054d",
19
+ "scripts": {
20
+ "pnpify": "yarn dlx @yarnpkg/sdks vscode"
21
+ },
22
+ "dependencies": {
23
+ "@stylistic/eslint-plugin": "^2.9.0",
24
+ "eslint-plugin-simple-import-sort": "^12.1.1",
25
+ "typescript-eslint": "^8.11.0"
26
+ },
27
+ "devDependencies": {
28
+ "@eslint/js": "^9.13.0",
29
+ "@types/eslint-plugin-jsx-a11y": "^6.9.0",
30
+ "@types/eslint__js": "^8.42.3",
31
+ "@types/node": "^22.7.8",
32
+ "eslint": "^9.13.0",
33
+ "eslint-plugin-jsx-a11y": "^6.10.1",
34
+ "eslint-plugin-react": "^7.37.1",
35
+ "eslint-plugin-react-hooks": "^5.0.0",
36
+ "typescript": "^5.6.3"
37
+ },
38
+ "peerDependencies": {
39
+ "eslint": "^9.13.0",
40
+ "eslint-plugin-jsx-a11y": "^6.10.1",
41
+ "eslint-plugin-react": "^7.37.1",
42
+ "eslint-plugin-react-hooks": "^5.0.0",
43
+ "typescript": "^5.6.3"
44
+ },
45
+ "peerDependenciesMeta": {
46
+ "eslint-plugin-jsx-a11y": {
47
+ "optional": true
48
+ },
49
+ "eslint-plugin-react": {
50
+ "optional": true
51
+ },
52
+ "eslint-plugin-react-hooks": {
53
+ "optional": true
54
+ }
55
+ }
56
+ }
package/shared.js ADDED
@@ -0,0 +1,134 @@
1
+ import eslint from '@eslint/js';
2
+ import stylistic from '@stylistic/eslint-plugin';
3
+ import simpleImportSort from 'eslint-plugin-simple-import-sort';
4
+ import tsEslint from 'typescript-eslint';
5
+
6
+ const stylisticCustomized = stylistic.configs.customize({
7
+ flat: true,
8
+ indent: 'tab',
9
+ semi: true,
10
+ jsx: false,
11
+ braceStyle: '1tbs',
12
+ quoteProps: 'as-needed',
13
+ });
14
+
15
+ /** @type {typeof import('typescript-eslint').configs.all} */
16
+ const shared = [
17
+ //
18
+ // eslint
19
+ //
20
+ eslint.configs.recommended,
21
+ {
22
+ rules: {
23
+ 'object-shorthand': ['error', 'always', { avoidQuotes: true }],
24
+ 'no-param-reassign': ['error', {
25
+ ignorePropertyModificationsFor: [
26
+ 'request',
27
+ 'reply',
28
+ 'session',
29
+ 'state',
30
+ ],
31
+ props: true,
32
+ }],
33
+ 'no-void': ['error', { allowAsStatement: true }],
34
+ yoda: ['error', 'never', { exceptRange: true }],
35
+ },
36
+ },
37
+ //
38
+ // typescript-eslint
39
+ //
40
+ ...tsEslint.configs.recommendedTypeChecked,
41
+ ...tsEslint.configs.stylisticTypeChecked,
42
+ {
43
+ ...tsEslint.configs.disableTypeChecked,
44
+ files: ['*.cjs', '*.js'],
45
+ },
46
+ {
47
+ languageOptions: {
48
+ parserOptions: {
49
+ projectService: true,
50
+ ecmaVersion: 'latest',
51
+ },
52
+ },
53
+ rules: {
54
+ '@typescript-eslint/array-type': ['error', {
55
+ default: 'array-simple',
56
+ }],
57
+ '@typescript-eslint/consistent-type-assertions': ['error', {
58
+ assertionStyle: 'as',
59
+ objectLiteralTypeAssertions: 'allow-as-parameter',
60
+ }],
61
+ '@typescript-eslint/consistent-type-definitions': 0,
62
+ '@typescript-eslint/no-unused-vars': 0,
63
+ '@typescript-eslint/no-empty-function': 0,
64
+ '@typescript-eslint/no-misused-promises': ['error', {
65
+ checksVoidReturn: false,
66
+ }],
67
+ '@typescript-eslint/no-unnecessary-type-arguments': 'warn',
68
+ '@typescript-eslint/no-shadow': 'error',
69
+ '@typescript-eslint/promise-function-async': 'error',
70
+ },
71
+ },
72
+ //
73
+ // stylistic
74
+ //
75
+ stylistic.configs['disable-legacy'],
76
+ // TODO: why rules are overwritten
77
+ // stylisticCustomized
78
+ {
79
+ ...stylisticCustomized,
80
+ rules: {
81
+ ...stylisticCustomized.rules,
82
+ '@stylistic/arrow-parens': ['error', 'as-needed', {
83
+ requireForBlockBody: true,
84
+ }],
85
+ '@stylistic/linebreak-style': ['error', 'windows'],
86
+ '@stylistic/max-len': ['error', { code: 120 }],
87
+ '@stylistic/no-multiple-empty-lines': ['error', {
88
+ max: 3,
89
+ maxBOF: 0,
90
+ maxEOF: 1,
91
+ }],
92
+ '@stylistic/max-statements-per-line': 0,
93
+ '@stylistic/indent-binary-ops': 0,
94
+ },
95
+ },
96
+ //
97
+ // simple-import-sort
98
+ //
99
+ {
100
+ plugins: {
101
+ 'simple-import-sort': simpleImportSort,
102
+ },
103
+ rules: {
104
+ 'simple-import-sort/imports': ['warn', {
105
+ groups: [
106
+ // Side effect imports.
107
+ ['^\\u0000'],
108
+ [
109
+ '^node:',
110
+ 'react',
111
+ // Things that start with a letter (or digit or underscore), or `@` followed by a letter.
112
+ '^@?\\w',
113
+ ],
114
+ // Absolute imports and other imports such as Vue-style `@/foo`.
115
+ ['^'],
116
+ [
117
+ // ../whatever/
118
+ '^\\.\\./(?=.*/)',
119
+ // ../
120
+ '^\\.\\./',
121
+ ],
122
+ [
123
+ // ./whatever/
124
+ '^\\./(?=.*/)',
125
+ // ./
126
+ '^\\./',
127
+ ],
128
+ ],
129
+ }],
130
+ },
131
+ },
132
+ ];
133
+
134
+ export default shared;