eslint-plugin-nextjs 0.1.0 → 0.1.2

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
@@ -9,7 +9,7 @@
9
9
 
10
10
  ## Overview
11
11
 
12
- This is a unofficial fork of `@next/eslint-plugin-next` with TypeScript and ESLint v9 support. I have no association with Vercel or the Next.js team. I just needed an updated version of the plugin for my style guide, `js-style-kit`.
12
+ This is a unofficial fork of [`@next/eslint-plugin-next`](https://www.npmjs.com/package/@next/eslint-plugin-next) with TypeScript and ESLint v9 support. I have no association with Vercel or the Next.js team. I just needed an updated version of the plugin for my style guide, [`js-style-kit`](https://js-style-kit.mintlify.app/introduction).
13
13
 
14
14
  If you're using `eslint-config-next`, you _do not_ need this plugin.
15
15
  You only need this plugin if you're rolling your own ESLint config.
@@ -21,11 +21,64 @@ You only need this plugin if you're rolling your own ESLint config.
21
21
  ## Installation
22
22
 
23
23
  ```bash
24
- npm i eslint-plugin-nextjs -D
24
+ npm i eslint eslint-plugin-nextjs -D
25
25
  # or
26
- yarn add eslint-plugin-nextjs -D
26
+ yarn add eslint eslint-plugin-nextjs -D
27
27
  # or
28
- pnpm add eslint-plugin-nextjs -D
28
+ pnpm add eslint eslint-plugin-nextjs -D
29
29
  # or
30
- bun add eslint-plugin-nextjs -d
30
+ bun add eslint eslint-plugin-nextjs -d
31
31
  ```
32
+
33
+ ## Usage
34
+
35
+ > **Note**: The API _will_ break in v1. I want to clean up this API follow ESLint standards.
36
+
37
+ This plugin ships two configs for both legacy and flat ESLint configuration formats:
38
+
39
+ - "recommended" or "recommended/flat" - includes most rules from Next.js
40
+ - "core-web-vitals" or "core-web-vitals/flat" - same thing but two rules get upgraded to errors 🤷‍♂️
41
+
42
+ You probably want Core Web Vitals (that's what ships inside of `eslint-config-next`), but you never need both.
43
+
44
+ ### Legacy Config
45
+
46
+ ```js
47
+ {
48
+ extends: ["nextjs/core-web-vitals"],
49
+ }
50
+ ```
51
+
52
+ ### Flat Config
53
+
54
+ ```js
55
+ import nextjs from "eslint-plugin-nextjs";
56
+
57
+ export default [
58
+ // ... other configs
59
+ nextjs.configs["core-web-vitals/flat"],
60
+ ];
61
+ ```
62
+
63
+ ### Custom Config
64
+
65
+ ```js
66
+ import nextjs from "eslint-plugin-nextjs";
67
+
68
+ export default [
69
+ // ... other configs
70
+ {
71
+ plugins: {
72
+ nextjs,
73
+ },
74
+ rules: {
75
+ "nextjs/google-font-display": "warn",
76
+ "nextjs/no-img-element": "warn",
77
+ },
78
+ },
79
+ ];
80
+ ```
81
+
82
+ ## Rules
83
+
84
+ See Vercel's [documentation](https://nextjs.org/docs/app/api-reference/config/eslint#rules) for rule details. I'll add a proper rule table here in the future.
package/dist/index.cjs CHANGED
@@ -6,8 +6,8 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
8
  var __export = (target, all) => {
9
- for (var name2 in all)
10
- __defProp(target, name2, { get: all[name2], enumerable: true });
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
11
  };
12
12
  var __copyProps = (to, from, except, desc) => {
13
13
  if (from && typeof from === "object" || typeof from === "function") {
@@ -587,8 +587,8 @@ var noHeadImportInDocument = defineRule({
587
587
  if (!document) {
588
588
  return;
589
589
  }
590
- const { dir, name: name2 } = path4.parse(document);
591
- if (name2.startsWith("_document") || dir === "/_document" && name2 === "index") {
590
+ const { dir, name } = path4.parse(document);
591
+ if (name.startsWith("_document") || dir === "/_document" && name === "index") {
592
592
  context.report({
593
593
  message: `\`next/head\` should not be imported in \`pages${document}\`. Use \`<Head />\` from \`next/document\` instead. See: ${url12}`,
594
594
  node
@@ -1067,8 +1067,8 @@ var noStyledJsxInDocument = defineRule({
1067
1067
  if (!document) {
1068
1068
  return;
1069
1069
  }
1070
- const { dir, name: name2 } = path8.parse(document);
1071
- if (!(name2.startsWith("_document") || dir === "/_document" && name2 === "index")) {
1070
+ const { dir, name } = path8.parse(document);
1071
+ if (!(name.startsWith("_document") || dir === "/_document" && name === "index")) {
1072
1072
  return;
1073
1073
  }
1074
1074
  if (node.name.name === "style" && node.attributes.find(
@@ -1202,17 +1202,17 @@ var minDistance = (a, b) => {
1202
1202
  };
1203
1203
  var noTypos = defineRule({
1204
1204
  create: (context) => {
1205
- const checkTypos = (node, name2) => {
1206
- if (NEXT_EXPORT_FUNCTIONS.includes(name2)) {
1205
+ const checkTypos = (node, name) => {
1206
+ if (NEXT_EXPORT_FUNCTIONS.includes(name)) {
1207
1207
  return;
1208
1208
  }
1209
1209
  const potentialTypos = NEXT_EXPORT_FUNCTIONS.map((o) => ({
1210
- distance: minDistance(o, name2) ?? Infinity,
1210
+ distance: minDistance(o, name) ?? Infinity,
1211
1211
  option: o
1212
1212
  })).filter(({ distance }) => distance <= THRESHOLD && distance > 0).sort((a, b) => a.distance - b.distance);
1213
1213
  if (potentialTypos.length) {
1214
1214
  context.report({
1215
- message: `${name2} may be a typo. Did you mean ${potentialTypos[0]?.option}?`,
1215
+ message: `${name} may be a typo. Did you mean ${potentialTypos[0]?.option}?`,
1216
1216
  node
1217
1217
  });
1218
1218
  }
@@ -1390,81 +1390,71 @@ var noUnwantedPolyfillio = defineRule({
1390
1390
  });
1391
1391
 
1392
1392
  // src/index.ts
1393
- var name = "nextjs";
1394
1393
  var plugin = {
1395
- name,
1396
1394
  rules: {
1397
- [`${name}/google-font-display`]: googleFontDisplay,
1398
- [`${name}/google-font-preconnect`]: googleFontPreconnect,
1399
- [`${name}/inline-script-id`]: inlineScriptId,
1400
- [`${name}/next-script-for-ga`]: nextScriptForGa,
1401
- [`${name}/no-assign-module-variable`]: noAssignModuleVariable,
1402
- [`${name}/no-async-client-component`]: noAsyncClientComponent,
1403
- [`${name}/no-before-interactive-script-outside-document`]: noBeforeInteractiveScriptOutsideDocument,
1404
- [`${name}/no-css-tags`]: noCssTags,
1405
- [`${name}/no-document-import-in-page`]: noDocumentImportInPage,
1406
- [`${name}/no-duplicate-head`]: noDuplicateHead,
1407
- [`${name}/no-head-element`]: noHeadElement,
1408
- [`${name}/no-head-import-in-document`]: noHeadImportInDocument,
1409
- [`${name}/no-html-link-for-pages`]: noHtmlLinkForPages,
1410
- [`${name}/no-img-element`]: noImgElement,
1411
- [`${name}/no-page-custom-font`]: noPageCustomFont,
1412
- [`${name}/no-script-component-in-head`]: noScriptComponentInHead,
1413
- [`${name}/no-styled-jsx-in-document`]: noStyledJsxInDocument,
1414
- [`${name}/no-sync-scripts`]: noSyncScripts,
1415
- [`${name}/no-title-in-document-head`]: noTitleInDocumentHead,
1416
- [`${name}/no-typos`]: noTypos,
1417
- [`${name}/no-unwanted-polyfillio`]: noUnwantedPolyfillio
1395
+ "google-font-display": googleFontDisplay,
1396
+ "google-font-preconnect": googleFontPreconnect,
1397
+ "inline-script-id": inlineScriptId,
1398
+ "next-script-for-ga": nextScriptForGa,
1399
+ "no-assign-module-variable": noAssignModuleVariable,
1400
+ "no-async-client-component": noAsyncClientComponent,
1401
+ "no-before-interactive-script-outside-document": noBeforeInteractiveScriptOutsideDocument,
1402
+ "no-css-tags": noCssTags,
1403
+ "no-document-import-in-page": noDocumentImportInPage,
1404
+ "no-duplicate-head": noDuplicateHead,
1405
+ "no-head-element": noHeadElement,
1406
+ "no-head-import-in-document": noHeadImportInDocument,
1407
+ "no-html-link-for-pages": noHtmlLinkForPages,
1408
+ "no-img-element": noImgElement,
1409
+ "no-page-custom-font": noPageCustomFont,
1410
+ "no-script-component-in-head": noScriptComponentInHead,
1411
+ "no-styled-jsx-in-document": noStyledJsxInDocument,
1412
+ "no-sync-scripts": noSyncScripts,
1413
+ "no-title-in-document-head": noTitleInDocumentHead,
1414
+ "no-typos": noTypos,
1415
+ "no-unwanted-polyfillio": noUnwantedPolyfillio
1418
1416
  }
1419
1417
  };
1420
1418
  var recommendedRules = {
1421
1419
  // warnings
1422
- "nextjs/google-font-display": "warn",
1423
- "nextjs/google-font-preconnect": "warn",
1420
+ "google-font-display": "warn",
1421
+ "google-font-preconnect": "warn",
1424
1422
  // errors
1425
- "nextjs/inline-script-id": "error",
1426
- "nextjs/next-script-for-ga": "warn",
1427
- "nextjs/no-assign-module-variable": "error",
1428
- "nextjs/no-async-client-component": "warn",
1429
- "nextjs/no-before-interactive-script-outside-document": "warn",
1430
- "nextjs/no-css-tags": "warn",
1431
- "nextjs/no-document-import-in-page": "error",
1432
- "nextjs/no-duplicate-head": "error",
1433
- "nextjs/no-head-element": "warn",
1434
- "nextjs/no-head-import-in-document": "error",
1435
- "nextjs/no-html-link-for-pages": "warn",
1436
- "nextjs/no-img-element": "warn",
1437
- "nextjs/no-page-custom-font": "warn",
1438
- "nextjs/no-script-component-in-head": "error",
1439
- "nextjs/no-styled-jsx-in-document": "warn",
1440
- "nextjs/no-sync-scripts": "warn",
1441
- "nextjs/no-title-in-document-head": "warn",
1442
- "nextjs/no-typos": "warn",
1443
- "nextjs/no-unwanted-polyfillio": "warn"
1423
+ "inline-script-id": "error",
1424
+ "next-script-for-ga": "warn",
1425
+ "no-assign-module-variable": "error",
1426
+ "no-async-client-component": "warn",
1427
+ "no-before-interactive-script-outside-document": "warn",
1428
+ "no-css-tags": "warn",
1429
+ "no-document-import-in-page": "error",
1430
+ "no-duplicate-head": "error",
1431
+ "no-head-element": "warn",
1432
+ "no-head-import-in-document": "error",
1433
+ "no-html-link-for-pages": "warn",
1434
+ "no-img-element": "warn",
1435
+ "no-page-custom-font": "warn",
1436
+ "no-script-component-in-head": "error",
1437
+ "no-styled-jsx-in-document": "warn",
1438
+ "no-sync-scripts": "warn",
1439
+ "no-title-in-document-head": "warn",
1440
+ "no-typos": "warn",
1441
+ "no-unwanted-polyfillio": "warn"
1444
1442
  };
1445
1443
  var coreWebVitalsRules = {
1446
1444
  ...recommendedRules,
1447
- "nextjs/no-html-link-for-pages": "error",
1448
- "nextjs/no-sync-scripts": "error"
1445
+ "no-html-link-for-pages": "error",
1446
+ "no-sync-scripts": "error"
1449
1447
  };
1450
- var createRuleConfig = (pluginName, rules2, isFlat = false) => {
1448
+ var createRuleConfig = (rules2, isFlat = false) => {
1451
1449
  return {
1452
- plugins: isFlat ? { [pluginName]: plugin } : [pluginName],
1450
+ plugins: isFlat ? { nextjs: plugin } : ["nextjs"],
1453
1451
  rules: rules2
1454
1452
  };
1455
1453
  };
1456
- var recommendedFlatConfig = createRuleConfig(name, recommendedRules, true);
1457
- var recommendedLegacyConfig = createRuleConfig(name, recommendedRules, false);
1458
- var coreWebVitalsFlatConfig = createRuleConfig(
1459
- name,
1460
- coreWebVitalsRules,
1461
- true
1462
- );
1463
- var coreWebVitalsLegacyConfig = createRuleConfig(
1464
- name,
1465
- coreWebVitalsRules,
1466
- false
1467
- );
1454
+ var recommendedFlatConfig = createRuleConfig(recommendedRules, true);
1455
+ var recommendedLegacyConfig = createRuleConfig(recommendedRules, false);
1456
+ var coreWebVitalsFlatConfig = createRuleConfig(coreWebVitalsRules, true);
1457
+ var coreWebVitalsLegacyConfig = createRuleConfig(coreWebVitalsRules, false);
1468
1458
  var index_default = {
1469
1459
  ...plugin,
1470
1460
  configs: {
@@ -1484,7 +1474,8 @@ var index_default = {
1484
1474
  * Flat config (ESLint v9+) with recommended rules
1485
1475
  */
1486
1476
  "recommended/flat": recommendedFlatConfig
1487
- }
1477
+ },
1478
+ name: "nextjs"
1488
1479
  };
1489
1480
  var rules = plugin.rules;
1490
1481
  // Annotate the CommonJS export names for ESM import in node: