@isentinel/eslint-config 0.3.0

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019-PRESENT Anthony Fu<https://github.com/antfu>
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,286 @@
1
+ # @isentinel/eslint-config
2
+
3
+ <!-- - Single quotes, no semi
4
+ - Auto fix for formatting (aimed to be used standalone **without** Prettier)
5
+ - Designed to work with TypeScript, JSX, Vue out-of-box
6
+ - Lints also for json, yaml, markdown
7
+ - Sorted imports, dangling commas
8
+ - Reasonable defaults, best practices, only one-line of config
9
+ - Opinionated, but [very customizable](#customization)
10
+ - [ESLint Flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new), compose easily!
11
+ - Using [ESLint Stylistic](https://github.com/eslint-stylistic/eslint-stylistic)
12
+ - Respects `.gitignore` by default
13
+ - Optional [formatters](#formatters) support for CSS, HTML, TOML, etc.
14
+ - **Style principle**: Minimal for reading, stable for diff, consistent -->
15
+
16
+ <!-- > [!IMPORTANT]
17
+ > Since v1.0.0, this config is rewritten to the new [ESLint Flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new), check the [release note](https://github.com/antfu/eslint-config/releases/tag/v1.0.0) for more details. -->
18
+
19
+ ## Usage
20
+
21
+ ### Install
22
+
23
+ ```bash
24
+ npm i -D eslint @isentinel/eslint-config
25
+ ```
26
+
27
+ ### Create config file
28
+
29
+ With [`"type": "module"`](https://nodejs.org/api/packages.html#type) in `package.json` (recommended):
30
+
31
+ ```js
32
+ // eslint.config.ts
33
+ import style from "@isentinel/eslint-config";
34
+
35
+ export default style();
36
+ ```
37
+
38
+ > Note that `.eslintignore` no longer works in Flat config, see
39
+ > [customization](#customization) for more details.
40
+
41
+ > [!TIP]
42
+ > ESLint only detects `eslint.config.js` as the flat config entry, meaning you need to put `type: module` in your `package.json`. `eslint.config.ts`, you can install [`eslint-ts-patch`](https://github.com/antfu/eslint-ts-patch) to fix it.
43
+
44
+ ### Add script for package.json
45
+
46
+ For example:
47
+
48
+ ```json
49
+ {
50
+ "scripts": {
51
+ "lint": "eslint .",
52
+ "lint:fix": "eslint . --fix"
53
+ }
54
+ }
55
+ ```
56
+
57
+ ## VS Code support (auto fix)
58
+
59
+ Install [VS Code ESLint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)
60
+
61
+ Add the following settings to your `.vscode/settings.json`:
62
+
63
+ ```json
64
+ {
65
+ // Enable the ESlint flat config support
66
+ "eslint.experimental.useFlatConfig": true,
67
+
68
+ "editor.formatOnSave": false,
69
+
70
+ // Auto fix
71
+ "editor.codeActionsOnSave": {
72
+ "source.fixAll.eslint": "always",
73
+ "source.organizeImports": "never"
74
+ },
75
+
76
+ // Silent the stylistic rules in you IDE, but still auto fix them
77
+ "eslint.rules.customizations": [
78
+ { "rule": "style/*", "severity": "off" },
79
+ { "rule": "format/*", "severity": "off" },
80
+ { "rule": "*-indent", "severity": "off" },
81
+ { "rule": "*-spacing", "severity": "off" },
82
+ { "rule": "*-spaces", "severity": "off" },
83
+ { "rule": "*-order", "severity": "off" },
84
+ { "rule": "*-dangle", "severity": "off" },
85
+ { "rule": "*-newline", "severity": "off" },
86
+ { "rule": "*quotes", "severity": "off" },
87
+ { "rule": "*semi", "severity": "off" }
88
+ ],
89
+
90
+ // Enable eslint for all supported languages
91
+ "eslint.validate": [
92
+ "typescript",
93
+ "typescriptreact",
94
+ "markdown",
95
+ "json",
96
+ "jsonc",
97
+ "yaml"
98
+ ]
99
+ }
100
+ ```
101
+
102
+ ## Customization
103
+
104
+ Normally you only need to import the `style` preset:
105
+
106
+ ```ts
107
+ // eslint.config.ts
108
+ import style from "@isentinel/eslint-config";
109
+
110
+ export default style();
111
+ ```
112
+
113
+ And that's it! Or you can configure each integration individually, for example:
114
+
115
+ ```ts
116
+ // eslint.config.ts
117
+ import style from "@isentinel/eslint-config";
118
+
119
+ export default style({
120
+ // `.eslintignore` is no longer supported in Flat config, use `ignores`
121
+ // instead
122
+ ignores: [
123
+ "./fixtures",
124
+ // ...globs
125
+ ],
126
+
127
+ // Provide TypeScript parser options for access to type checking lints.
128
+ typescript: {
129
+ parserOptions: {
130
+ ecmaVersion: 2018,
131
+ jsx: true,
132
+ sourceType: "module",
133
+ useJSXTextNode: true,
134
+ },
135
+ tsconfigPath: "./tsconfig.json",
136
+ },
137
+
138
+ // Disable yaml support
139
+ yaml: false,
140
+ });
141
+ ```
142
+
143
+ The `style` factory function also accepts any number of arbitrary custom config overrides:
144
+
145
+ ```ts
146
+ // eslint.config.ts
147
+ import style from "@isentinel/eslint-config";
148
+
149
+ export default style(
150
+ {
151
+ // Configures for isentinel's config
152
+ },
153
+
154
+ // From the second arguments they are ESLint Flat Configs
155
+ // you can have multiple configs
156
+ {
157
+ files: ["**/*.ts"],
158
+ rules: {},
159
+ },
160
+ {
161
+ rules: {},
162
+ },
163
+ );
164
+ ```
165
+
166
+ Check out the [configs](https://github.com/christopher-buss/roblox-ts-eslint-config/tree/main/src/configs) and [factory](https://github.com/christopher-buss/roblox-ts-eslint-config/blob/main/src/factory.ts) for more details.
167
+
168
+ > Thanks to [antfu/eslint-config](https://github.com/antfu/eslint-config) and [sxzz/eslint-config](https://github.com/sxzz/eslint-config) for the inspiration and reference.
169
+
170
+ ### Plugins Renaming
171
+
172
+ Since flat config requires us to explicitly provide the plugin names (instead of the mandatory convention from npm package name), we renamed some plugins to make the overall scope more consistent and easier to write.
173
+
174
+ | New Prefix | Original Prefix | Source Plugin |
175
+ | ---------- | ---------------------- | ------------------------------------------------------------------------------------------ |
176
+ | `import/*` | `i/*` | [eslint-plugin-i](https://github.com/un-es/eslint-plugin-i) |
177
+ | `node/*` | `n/*` | [eslint-plugin-n](https://github.com/eslint-community/eslint-plugin-n) |
178
+ | `yaml/*` | `yml/*` | [eslint-plugin-yml](https://github.com/ota-meshi/eslint-plugin-yml) |
179
+ | `ts/*` | `@typescript-eslint/*` | [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint) |
180
+ | `style/*` | `@stylistic/*` | [@stylistic/eslint-plugin](https://github.com/eslint-stylistic/eslint-stylistic) |
181
+
182
+ When you want to override rules, or disable them inline, you need to update to the new prefix:
183
+
184
+ ```diff
185
+ -// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
186
+ +// eslint-disable-next-line ts/consistent-type-definitions
187
+ type foo = { bar: 2 }
188
+ ```
189
+
190
+ ### Optional Configs
191
+
192
+ We provide some optional configs for specific use cases, that we don't include their dependencies by default.
193
+
194
+ #### React
195
+
196
+ To enable React support, you need to explicitly turn it on:
197
+
198
+ ```js
199
+ // eslint.config.ts
200
+ import style from "@isentinel/eslint-config";
201
+
202
+ export default style({
203
+ react: true,
204
+ });
205
+ ```
206
+
207
+ Running `npx eslint` should prompt you to install the required dependencies, otherwise, you can install them manually:
208
+
209
+ ```bash
210
+ npm i -D eslint-plugin-react eslint-plugin-react-hooks
211
+ ```
212
+
213
+ ### Optional Rules
214
+
215
+ This config also provides some optional plugins/rules for extended usages.
216
+
217
+ #### `perfectionist` (sorting)
218
+
219
+ This plugin [`eslint-plugin-perfectionist`](https://github.com/azat-io/eslint-plugin-perfectionist) allows you to sorted object keys, imports, etc, with auto-fix.
220
+
221
+ The plugin is installed and some rules are enabled by default, but these rules
222
+ can be disabled or overridden by your own config. For example, I personally have
223
+ sort-objects set to:
224
+
225
+ ```js
226
+ // eslint.config.ts
227
+ import style from "@isentinel/eslint-config";
228
+
229
+ export default style({
230
+ rules: {
231
+ "perfectionist/sort-objects": [
232
+ "warn",
233
+ {
234
+ "custom-groups": {
235
+ id: "id",
236
+ name: "name",
237
+ "react-props": ["children", "ref"],
238
+ },
239
+ groups: ["id", "name", "unknown", "react-props"],
240
+ order: "asc",
241
+ "partition-by-comment": "Part:**",
242
+ type: "natural",
243
+ },
244
+ ],
245
+ },
246
+ });
247
+ ```
248
+
249
+ ### Lint Staged
250
+
251
+ If you want to apply lint and auto-fix before every commit, you can add the following to your `package.json`:
252
+
253
+ ```json
254
+ {
255
+ "simple-git-hooks": {
256
+ "pre-commit": "npm lint-staged"
257
+ },
258
+ "lint-staged": {
259
+ "*": "eslint --fix"
260
+ }
261
+ }
262
+ ```
263
+
264
+ and then
265
+
266
+ ```bash
267
+ npm i -D lint-staged simple-git-hooks
268
+ ```
269
+
270
+ ## View what rules are enabled
271
+
272
+ There is a visual tool to help you view what rules are enabled in your project and apply them to what files, [eslint-flat-config-viewer](https://github.com/antfu/eslint-flat-config-viewer)
273
+
274
+ Go to your project root that contains `eslint.config.ts` and run:
275
+
276
+ ```bash
277
+ npx eslint-flat-config-viewer
278
+ ```
279
+
280
+ ### I prefer XXX...
281
+
282
+ Sure, you can configure and override rules locally in your project to fit your
283
+ needs. If that still does not work for you, you can always fork this repo and
284
+ maintain your own. I am open to PRs that help improve the overall experience for
285
+ developers, and there may still be rules activated that do not apply to the
286
+ roblox-ts ecosystem.
package/bin/index.js ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+
3
+ import "../dist/cli.js";