@infernodesign/eslint-config 2.8.0 → 2.10.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 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 fs from "node:fs/promises";
3
- import fs$1 from "node: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.8.0";
11
+ var version = "2.10.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"],
@@ -153,18 +158,17 @@ function isGitClean() {
153
158
  //#endregion
154
159
  //#region src/cli/stages/update-eslint-files.ts
155
160
  const ESLINT_OR_PRETTIER = /eslint|prettier/;
156
- const ESLINT_CONFIG = /eslint\.config\./;
157
161
  async function updateEslintFiles(result) {
158
162
  const cwd = process.cwd();
159
163
  const pathESLintIgnore = path.join(cwd, ".eslintignore");
160
164
  const pathPackageJSON = path.join(cwd, "package.json");
161
- const pkgContent = await fs.readFile(pathPackageJSON, "utf-8");
165
+ const pkgContent = await fsPromises.readFile(pathPackageJSON, "utf-8");
162
166
  const configFileName = JSON.parse(pkgContent).type === "module" ? "eslint.config.js" : "eslint.config.mjs";
163
167
  const pathFlatConfig = path.join(cwd, configFileName);
164
168
  const eslintIgnores = [];
165
- if (fs$1.existsSync(pathESLintIgnore)) {
169
+ if (fs.existsSync(pathESLintIgnore)) {
166
170
  p.log.step(c.cyan`Migrating existing .eslintignore`);
167
- const globs = parse(await fs.readFile(pathESLintIgnore, "utf-8")).globs();
171
+ const globs = parse(await fsPromises.readFile(pathESLintIgnore, "utf-8")).globs();
168
172
  for (const glob of globs) if (glob.type === "ignore") eslintIgnores.push(...glob.patterns);
169
173
  else if (glob.type === "unignore") eslintIgnores.push(...glob.patterns.map((pattern) => `!${pattern}`));
170
174
  }
@@ -174,30 +178,31 @@ async function updateEslintFiles(result) {
174
178
  if (result.extra.includes("unocss")) configLines.push("unocss: true,");
175
179
  for (const framework of result.frameworks) configLines.push(`${framework}: true,`);
176
180
  const eslintConfigContent = getEslintConfigContent(configLines.map((i) => ` ${i}`).join("\n"), []);
177
- await fs.writeFile(pathFlatConfig, eslintConfigContent);
181
+ await fsPromises.writeFile(pathFlatConfig, eslintConfigContent);
178
182
  p.log.success(c.green`Created ${configFileName}`);
179
- const files = fs$1.readdirSync(cwd);
183
+ const files = fs.readdirSync(cwd);
180
184
  const legacyConfig = [];
181
185
  files.forEach((file) => {
182
- if (ESLINT_OR_PRETTIER.test(file) && !ESLINT_CONFIG.test(file)) legacyConfig.push(file);
186
+ if (ESLINT_OR_PRETTIER.test(file) && !file.includes("eslint.config.")) legacyConfig.push(file);
183
187
  });
184
188
  if (legacyConfig.length) p.note(c.dim(legacyConfig.join(", ")), "You can now remove those files manually");
185
189
  }
186
190
  //#endregion
187
191
  //#region src/cli/constants-generated.ts
188
192
  const versionsMap = {
189
- "@eslint-react/eslint-plugin": "^5.8.12",
190
- "@next/eslint-plugin-next": "^16.2.7",
191
- "@unocss/eslint-plugin": "^66.7.0",
192
- "astro-eslint-parser": "^1.4.0",
193
- "eslint": "^10.4.1",
194
- "eslint-plugin-astro": "^1.7.0",
195
- "eslint-plugin-better-tailwindcss": "^4.5.0",
193
+ "@eslint-react/eslint-plugin": "^5.10.4",
194
+ "@next/eslint-plugin-next": "^16.2.10",
195
+ "@sanity-labs/eslint-plugin": "^1.0.0",
196
+ "@unocss/eslint-plugin": "^66.7.4",
197
+ "astro-eslint-parser": "^2.1.0",
198
+ "eslint": "^10.6.0",
199
+ "eslint-plugin-astro": "^2.1.1",
200
+ "eslint-plugin-better-tailwindcss": "^4.6.1",
196
201
  "eslint-plugin-format": "^2.0.1",
197
- "eslint-plugin-react-refresh": "^0.5.2",
202
+ "eslint-plugin-react-refresh": "^0.5.3",
198
203
  "eslint-plugin-solid": "^0.14.5",
199
- "eslint-plugin-storybook": "^10.4.2",
200
- "eslint-plugin-svelte": "^3.19.0",
204
+ "eslint-plugin-storybook": "^10.4.6",
205
+ "eslint-plugin-svelte": "^3.20.0",
201
206
  "prettier-plugin-astro": "^0.14.1",
202
207
  "prettier-plugin-slidev": "^1.0.5",
203
208
  "svelte-eslint-parser": "^1.8.0"
@@ -208,7 +213,7 @@ async function updatePackageJson(result) {
208
213
  const cwd = process.cwd();
209
214
  const pathPackageJSON = path.join(cwd, "package.json");
210
215
  p.log.step(c.cyan`Bumping ${PACKAGE_NAME} to v${version}`);
211
- const pkgContent = await fs.readFile(pathPackageJSON, "utf-8");
216
+ const pkgContent = await fsPromises.readFile(pathPackageJSON, "utf-8");
212
217
  const pkg = JSON.parse(pkgContent);
213
218
  pkg.devDependencies ??= {};
214
219
  pkg.devDependencies[PACKAGE_NAME] = `^${version}`;
@@ -239,7 +244,7 @@ async function updatePackageJson(result) {
239
244
  });
240
245
  }
241
246
  if (addedPackages.length) p.note(c.dim(addedPackages.join(", ")), "Added packages");
242
- await fs.writeFile(pathPackageJSON, JSON.stringify(pkg, null, 2));
247
+ await fsPromises.writeFile(pathPackageJSON, JSON.stringify(pkg, null, 2));
243
248
  p.log.success(c.green`Changes wrote to package.json`);
244
249
  }
245
250
  //#endregion
@@ -250,16 +255,16 @@ async function updateVscodeSettings(result) {
250
255
  if (!result.updateVscodeSettings) return;
251
256
  const dotVscodePath = path.join(cwd, ".vscode");
252
257
  const settingsPath = path.join(dotVscodePath, "settings.json");
253
- if (!fs$1.existsSync(dotVscodePath)) await fs.mkdir(dotVscodePath, { recursive: true });
254
- if (!fs$1.existsSync(settingsPath)) {
255
- await fs.writeFile(settingsPath, `{${vscodeSettingsString}}\n`, "utf-8");
258
+ if (!fs.existsSync(dotVscodePath)) await fsPromises.mkdir(dotVscodePath, { recursive: true });
259
+ if (!fs.existsSync(settingsPath)) {
260
+ await fsPromises.writeFile(settingsPath, `{${vscodeSettingsString}}\n`, "utf-8");
256
261
  p.log.success(green`Created .vscode/settings.json`);
257
262
  } else {
258
- let settingsContent = await fs.readFile(settingsPath, "utf8");
263
+ let settingsContent = await fsPromises.readFile(settingsPath, "utf8");
259
264
  settingsContent = settingsContent.trim().replace(LAST_LINE_PATTERN, "");
260
265
  settingsContent += settingsContent.endsWith(",") || settingsContent.endsWith("{") ? "" : ",";
261
266
  settingsContent += `${vscodeSettingsString}}\n`;
262
- await fs.writeFile(settingsPath, settingsContent, "utf-8");
267
+ await fsPromises.writeFile(settingsPath, settingsContent, "utf-8");
263
268
  p.log.success(green`Updated .vscode/settings.json`);
264
269
  }
265
270
  }
@@ -269,7 +274,7 @@ async function run(options = {}) {
269
274
  const argSkipPrompt = !!process.env.SKIP_PROMPT || options.yes;
270
275
  const argTemplate = options.frameworks?.map((m) => m?.trim()).filter(Boolean);
271
276
  const argExtra = options.extra?.map((m) => m?.trim()).filter(Boolean);
272
- if (fs$1.existsSync(path.join(process.cwd(), "eslint.config.js"))) {
277
+ if (fs.existsSync(path.join(process.cwd(), "eslint.config.js"))) {
273
278
  p.log.warn(c.yellow`eslint.config.js already exists, migration wizard exited.`);
274
279
  return process.exit(1);
275
280
  }