@infernodesign/eslint-config 2.7.0 → 2.9.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/README.md +81 -1
- package/dist/cli.js +33 -27
- package/dist/index.d.ts +1435 -220
- package/dist/index.js +69 -9
- package/package.json +51 -44
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ Shared ESLint flat config presets for Inferno Design projects. Orignally forked
|
|
|
6
6
|
- Reasonable best practices and only one line of config.
|
|
7
7
|
- Designed to work with TypeScript, JSX, Vue, JSON, YAML, Toml, Markdown, etc. Out-of-box.
|
|
8
8
|
- Uses the [ESLint Flat Config](https://eslint.org/docs/latest/use/configure/configuration-files-new) for easy compilation.
|
|
9
|
-
- Optional [React](#react), [Next.js](#nextjs), [Svelte](#svelte), [UnoCSS](#unocss), [Astro](#astro), [Storybook](#storybook), [Solid](#solid) support, [TailwindCSS](#tailwindcss) support.
|
|
9
|
+
- Optional [React](#react), [Next.js](#nextjs), [Sanity](#sanity), [Svelte](#svelte), [UnoCSS](#unocss), [Astro](#astro), [Storybook](#storybook), [Solid](#solid) support, [TailwindCSS](#tailwindcss) support.
|
|
10
10
|
- Optional [formatters](#formatters) support for formatting CSS, HTML, XML, etc.
|
|
11
11
|
- **Style principle**: Minimal for reading, stable for diff, consistent
|
|
12
12
|
- Sorted imports, dangling commas
|
|
@@ -531,6 +531,86 @@ Running `npx eslint` should prompt you to install the required dependencies, oth
|
|
|
531
531
|
npm i -D @next/eslint-plugin-next
|
|
532
532
|
```
|
|
533
533
|
|
|
534
|
+
#### Sanity
|
|
535
|
+
|
|
536
|
+
To enable Sanity linting with the default recommended rules, explicitly turn it on:
|
|
537
|
+
|
|
538
|
+
```js
|
|
539
|
+
// eslint.config.js
|
|
540
|
+
import { config } from '@infernodesign/eslint-config'
|
|
541
|
+
|
|
542
|
+
export default config( {
|
|
543
|
+
sanity: true,
|
|
544
|
+
} )
|
|
545
|
+
```
|
|
546
|
+
|
|
547
|
+
Sanity support is powered by [`@sanity-labs/eslint-plugin`](https://github.com/sanity-labs/sanity-lint/tree/main/packages/eslint-plugin). It is an optional peer dependency, so projects that enable `sanity` must install it:
|
|
548
|
+
|
|
549
|
+
```bash
|
|
550
|
+
npm i -D @sanity-labs/eslint-plugin
|
|
551
|
+
```
|
|
552
|
+
|
|
553
|
+
You can choose a narrower preset for different Sanity project shapes:
|
|
554
|
+
|
|
555
|
+
```js
|
|
556
|
+
// eslint.config.js
|
|
557
|
+
import { config } from '@infernodesign/eslint-config'
|
|
558
|
+
|
|
559
|
+
export default config( {
|
|
560
|
+
// Recommended GROQ and schema rules for combined apps
|
|
561
|
+
sanity: {
|
|
562
|
+
preset: 'recommended',
|
|
563
|
+
},
|
|
564
|
+
} )
|
|
565
|
+
```
|
|
566
|
+
|
|
567
|
+
```js
|
|
568
|
+
// eslint.config.js
|
|
569
|
+
import { config } from '@infernodesign/eslint-config'
|
|
570
|
+
|
|
571
|
+
export default config( {
|
|
572
|
+
// GROQ rules only for web apps, frontends, or functions
|
|
573
|
+
sanity: {
|
|
574
|
+
preset: 'groq',
|
|
575
|
+
},
|
|
576
|
+
} )
|
|
577
|
+
```
|
|
578
|
+
|
|
579
|
+
```js
|
|
580
|
+
// eslint.config.js
|
|
581
|
+
import { config } from '@infernodesign/eslint-config'
|
|
582
|
+
|
|
583
|
+
export default config( {
|
|
584
|
+
// Schema rules only for a standalone Sanity Studio
|
|
585
|
+
sanity: {
|
|
586
|
+
preset: 'schema',
|
|
587
|
+
},
|
|
588
|
+
} )
|
|
589
|
+
```
|
|
590
|
+
|
|
591
|
+
Other available presets are `performance` for performance-focused GROQ rules and `strict` for enabling every Sanity rule as an error.
|
|
592
|
+
|
|
593
|
+
For schema-aware GROQ rules like `sanity/groq-invalid-type-filter` and `sanity/groq-unknown-field`, provide an extracted schema file. In monorepos, use `cwd` to resolve `schemaPath` from the nested Studio or app directory:
|
|
594
|
+
|
|
595
|
+
```js
|
|
596
|
+
// eslint.config.js
|
|
597
|
+
import { config } from '@infernodesign/eslint-config'
|
|
598
|
+
|
|
599
|
+
export default config( {
|
|
600
|
+
sanity: {
|
|
601
|
+
cwd: 'apps/studio',
|
|
602
|
+
preset: 'recommended',
|
|
603
|
+
schemaPath: 'schema.json',
|
|
604
|
+
},
|
|
605
|
+
} )
|
|
606
|
+
```
|
|
607
|
+
|
|
608
|
+
Generate `schema.json` with the Sanity CLI:
|
|
609
|
+
|
|
610
|
+
```bash
|
|
611
|
+
npx sanity schema extract
|
|
612
|
+
```
|
|
613
|
+
|
|
534
614
|
#### Storybook
|
|
535
615
|
|
|
536
616
|
To enable storybook support, you need to explicitly turn it on:
|
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as PACKAGE_NAME } from "./constants-BxEizS7D.js";
|
|
2
|
-
import
|
|
3
|
-
import fs
|
|
2
|
+
import fsPromises from "node:fs/promises";
|
|
3
|
+
import fs from "node:fs";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import * as p from "@clack/prompts";
|
|
6
6
|
import c, { green } from "ansis";
|
|
@@ -8,7 +8,7 @@ import { cac } from "cac";
|
|
|
8
8
|
import parse from "parse-gitignore";
|
|
9
9
|
import { execSync } from "node:child_process";
|
|
10
10
|
//#region package.json
|
|
11
|
-
var version = "2.
|
|
11
|
+
var version = "2.9.0";
|
|
12
12
|
//#endregion
|
|
13
13
|
//#region src/cli/constants.ts
|
|
14
14
|
const vscodeSettingsString = `
|
|
@@ -81,6 +81,10 @@ const frameworkOptions = [
|
|
|
81
81
|
label: c.cyan("React"),
|
|
82
82
|
value: "react"
|
|
83
83
|
},
|
|
84
|
+
{
|
|
85
|
+
label: c.red("Sanity"),
|
|
86
|
+
value: "sanity"
|
|
87
|
+
},
|
|
84
88
|
{
|
|
85
89
|
label: c.blue("Slidev"),
|
|
86
90
|
value: "slidev"
|
|
@@ -123,6 +127,7 @@ const dependenciesMap = {
|
|
|
123
127
|
nextjs: ["@next/eslint-plugin-next"],
|
|
124
128
|
node: [],
|
|
125
129
|
react: ["@eslint-react/eslint-plugin", "eslint-plugin-react-refresh"],
|
|
130
|
+
sanity: ["@sanity-labs/eslint-plugin"],
|
|
126
131
|
slidev: ["prettier-plugin-slidev"],
|
|
127
132
|
solid: ["eslint-plugin-solid"],
|
|
128
133
|
storybook: ["eslint-plugin-storybook"],
|
|
@@ -158,13 +163,13 @@ async function updateEslintFiles(result) {
|
|
|
158
163
|
const cwd = process.cwd();
|
|
159
164
|
const pathESLintIgnore = path.join(cwd, ".eslintignore");
|
|
160
165
|
const pathPackageJSON = path.join(cwd, "package.json");
|
|
161
|
-
const pkgContent = await
|
|
166
|
+
const pkgContent = await fsPromises.readFile(pathPackageJSON, "utf-8");
|
|
162
167
|
const configFileName = JSON.parse(pkgContent).type === "module" ? "eslint.config.js" : "eslint.config.mjs";
|
|
163
168
|
const pathFlatConfig = path.join(cwd, configFileName);
|
|
164
169
|
const eslintIgnores = [];
|
|
165
|
-
if (fs
|
|
170
|
+
if (fs.existsSync(pathESLintIgnore)) {
|
|
166
171
|
p.log.step(c.cyan`Migrating existing .eslintignore`);
|
|
167
|
-
const globs = parse(await
|
|
172
|
+
const globs = parse(await fsPromises.readFile(pathESLintIgnore, "utf-8")).globs();
|
|
168
173
|
for (const glob of globs) if (glob.type === "ignore") eslintIgnores.push(...glob.patterns);
|
|
169
174
|
else if (glob.type === "unignore") eslintIgnores.push(...glob.patterns.map((pattern) => `!${pattern}`));
|
|
170
175
|
}
|
|
@@ -174,9 +179,9 @@ async function updateEslintFiles(result) {
|
|
|
174
179
|
if (result.extra.includes("unocss")) configLines.push("unocss: true,");
|
|
175
180
|
for (const framework of result.frameworks) configLines.push(`${framework}: true,`);
|
|
176
181
|
const eslintConfigContent = getEslintConfigContent(configLines.map((i) => ` ${i}`).join("\n"), []);
|
|
177
|
-
await
|
|
182
|
+
await fsPromises.writeFile(pathFlatConfig, eslintConfigContent);
|
|
178
183
|
p.log.success(c.green`Created ${configFileName}`);
|
|
179
|
-
const files = fs
|
|
184
|
+
const files = fs.readdirSync(cwd);
|
|
180
185
|
const legacyConfig = [];
|
|
181
186
|
files.forEach((file) => {
|
|
182
187
|
if (ESLINT_OR_PRETTIER.test(file) && !ESLINT_CONFIG.test(file)) legacyConfig.push(file);
|
|
@@ -186,21 +191,22 @@ async function updateEslintFiles(result) {
|
|
|
186
191
|
//#endregion
|
|
187
192
|
//#region src/cli/constants-generated.ts
|
|
188
193
|
const versionsMap = {
|
|
189
|
-
"@eslint-react/eslint-plugin": "^5.
|
|
190
|
-
"@next/eslint-plugin-next": "^16.2.
|
|
191
|
-
"@
|
|
192
|
-
"
|
|
193
|
-
"eslint": "^
|
|
194
|
-
"eslint
|
|
195
|
-
"eslint-plugin-
|
|
194
|
+
"@eslint-react/eslint-plugin": "^5.9.3",
|
|
195
|
+
"@next/eslint-plugin-next": "^16.2.9",
|
|
196
|
+
"@sanity-labs/eslint-plugin": "^1.0.0",
|
|
197
|
+
"@unocss/eslint-plugin": "^66.7.3",
|
|
198
|
+
"astro-eslint-parser": "^2.1.0",
|
|
199
|
+
"eslint": "^10.5.0",
|
|
200
|
+
"eslint-plugin-astro": "^2.1.1",
|
|
201
|
+
"eslint-plugin-better-tailwindcss": "^4.6.0",
|
|
196
202
|
"eslint-plugin-format": "^2.0.1",
|
|
197
|
-
"eslint-plugin-react-refresh": "^0.5.
|
|
203
|
+
"eslint-plugin-react-refresh": "^0.5.3",
|
|
198
204
|
"eslint-plugin-solid": "^0.14.5",
|
|
199
|
-
"eslint-plugin-storybook": "^10.4.
|
|
200
|
-
"eslint-plugin-svelte": "^3.
|
|
205
|
+
"eslint-plugin-storybook": "^10.4.6",
|
|
206
|
+
"eslint-plugin-svelte": "^3.20.0",
|
|
201
207
|
"prettier-plugin-astro": "^0.14.1",
|
|
202
208
|
"prettier-plugin-slidev": "^1.0.5",
|
|
203
|
-
"svelte-eslint-parser": "^1.
|
|
209
|
+
"svelte-eslint-parser": "^1.8.0"
|
|
204
210
|
};
|
|
205
211
|
//#endregion
|
|
206
212
|
//#region src/cli/stages/update-package-json.ts
|
|
@@ -208,7 +214,7 @@ async function updatePackageJson(result) {
|
|
|
208
214
|
const cwd = process.cwd();
|
|
209
215
|
const pathPackageJSON = path.join(cwd, "package.json");
|
|
210
216
|
p.log.step(c.cyan`Bumping ${PACKAGE_NAME} to v${version}`);
|
|
211
|
-
const pkgContent = await
|
|
217
|
+
const pkgContent = await fsPromises.readFile(pathPackageJSON, "utf-8");
|
|
212
218
|
const pkg = JSON.parse(pkgContent);
|
|
213
219
|
pkg.devDependencies ??= {};
|
|
214
220
|
pkg.devDependencies[PACKAGE_NAME] = `^${version}`;
|
|
@@ -239,7 +245,7 @@ async function updatePackageJson(result) {
|
|
|
239
245
|
});
|
|
240
246
|
}
|
|
241
247
|
if (addedPackages.length) p.note(c.dim(addedPackages.join(", ")), "Added packages");
|
|
242
|
-
await
|
|
248
|
+
await fsPromises.writeFile(pathPackageJSON, JSON.stringify(pkg, null, 2));
|
|
243
249
|
p.log.success(c.green`Changes wrote to package.json`);
|
|
244
250
|
}
|
|
245
251
|
//#endregion
|
|
@@ -250,16 +256,16 @@ async function updateVscodeSettings(result) {
|
|
|
250
256
|
if (!result.updateVscodeSettings) return;
|
|
251
257
|
const dotVscodePath = path.join(cwd, ".vscode");
|
|
252
258
|
const settingsPath = path.join(dotVscodePath, "settings.json");
|
|
253
|
-
if (!fs
|
|
254
|
-
if (!fs
|
|
255
|
-
await
|
|
259
|
+
if (!fs.existsSync(dotVscodePath)) await fsPromises.mkdir(dotVscodePath, { recursive: true });
|
|
260
|
+
if (!fs.existsSync(settingsPath)) {
|
|
261
|
+
await fsPromises.writeFile(settingsPath, `{${vscodeSettingsString}}\n`, "utf-8");
|
|
256
262
|
p.log.success(green`Created .vscode/settings.json`);
|
|
257
263
|
} else {
|
|
258
|
-
let settingsContent = await
|
|
264
|
+
let settingsContent = await fsPromises.readFile(settingsPath, "utf8");
|
|
259
265
|
settingsContent = settingsContent.trim().replace(LAST_LINE_PATTERN, "");
|
|
260
266
|
settingsContent += settingsContent.endsWith(",") || settingsContent.endsWith("{") ? "" : ",";
|
|
261
267
|
settingsContent += `${vscodeSettingsString}}\n`;
|
|
262
|
-
await
|
|
268
|
+
await fsPromises.writeFile(settingsPath, settingsContent, "utf-8");
|
|
263
269
|
p.log.success(green`Updated .vscode/settings.json`);
|
|
264
270
|
}
|
|
265
271
|
}
|
|
@@ -269,7 +275,7 @@ async function run(options = {}) {
|
|
|
269
275
|
const argSkipPrompt = !!process.env.SKIP_PROMPT || options.yes;
|
|
270
276
|
const argTemplate = options.frameworks?.map((m) => m?.trim()).filter(Boolean);
|
|
271
277
|
const argExtra = options.extra?.map((m) => m?.trim()).filter(Boolean);
|
|
272
|
-
if (fs
|
|
278
|
+
if (fs.existsSync(path.join(process.cwd(), "eslint.config.js"))) {
|
|
273
279
|
p.log.warn(c.yellow`eslint.config.js already exists, migration wizard exited.`);
|
|
274
280
|
return process.exit(1);
|
|
275
281
|
}
|