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/dist/index.js CHANGED
@@ -550,8 +550,8 @@ var noHeadImportInDocument = defineRule({
550
550
  if (!document) {
551
551
  return;
552
552
  }
553
- const { dir, name: name2 } = path4.parse(document);
554
- if (name2.startsWith("_document") || dir === "/_document" && name2 === "index") {
553
+ const { dir, name } = path4.parse(document);
554
+ if (name.startsWith("_document") || dir === "/_document" && name === "index") {
555
555
  context.report({
556
556
  message: `\`next/head\` should not be imported in \`pages${document}\`. Use \`<Head />\` from \`next/document\` instead. See: ${url12}`,
557
557
  node
@@ -1030,8 +1030,8 @@ var noStyledJsxInDocument = defineRule({
1030
1030
  if (!document) {
1031
1031
  return;
1032
1032
  }
1033
- const { dir, name: name2 } = path8.parse(document);
1034
- if (!(name2.startsWith("_document") || dir === "/_document" && name2 === "index")) {
1033
+ const { dir, name } = path8.parse(document);
1034
+ if (!(name.startsWith("_document") || dir === "/_document" && name === "index")) {
1035
1035
  return;
1036
1036
  }
1037
1037
  if (node.name.name === "style" && node.attributes.find(
@@ -1165,17 +1165,17 @@ var minDistance = (a, b) => {
1165
1165
  };
1166
1166
  var noTypos = defineRule({
1167
1167
  create: (context) => {
1168
- const checkTypos = (node, name2) => {
1169
- if (NEXT_EXPORT_FUNCTIONS.includes(name2)) {
1168
+ const checkTypos = (node, name) => {
1169
+ if (NEXT_EXPORT_FUNCTIONS.includes(name)) {
1170
1170
  return;
1171
1171
  }
1172
1172
  const potentialTypos = NEXT_EXPORT_FUNCTIONS.map((o) => ({
1173
- distance: minDistance(o, name2) ?? Infinity,
1173
+ distance: minDistance(o, name) ?? Infinity,
1174
1174
  option: o
1175
1175
  })).filter(({ distance }) => distance <= THRESHOLD && distance > 0).sort((a, b) => a.distance - b.distance);
1176
1176
  if (potentialTypos.length) {
1177
1177
  context.report({
1178
- message: `${name2} may be a typo. Did you mean ${potentialTypos[0]?.option}?`,
1178
+ message: `${name} may be a typo. Did you mean ${potentialTypos[0]?.option}?`,
1179
1179
  node
1180
1180
  });
1181
1181
  }
@@ -1353,81 +1353,71 @@ var noUnwantedPolyfillio = defineRule({
1353
1353
  });
1354
1354
 
1355
1355
  // src/index.ts
1356
- var name = "nextjs";
1357
1356
  var plugin = {
1358
- name,
1359
1357
  rules: {
1360
- [`${name}/google-font-display`]: googleFontDisplay,
1361
- [`${name}/google-font-preconnect`]: googleFontPreconnect,
1362
- [`${name}/inline-script-id`]: inlineScriptId,
1363
- [`${name}/next-script-for-ga`]: nextScriptForGa,
1364
- [`${name}/no-assign-module-variable`]: noAssignModuleVariable,
1365
- [`${name}/no-async-client-component`]: noAsyncClientComponent,
1366
- [`${name}/no-before-interactive-script-outside-document`]: noBeforeInteractiveScriptOutsideDocument,
1367
- [`${name}/no-css-tags`]: noCssTags,
1368
- [`${name}/no-document-import-in-page`]: noDocumentImportInPage,
1369
- [`${name}/no-duplicate-head`]: noDuplicateHead,
1370
- [`${name}/no-head-element`]: noHeadElement,
1371
- [`${name}/no-head-import-in-document`]: noHeadImportInDocument,
1372
- [`${name}/no-html-link-for-pages`]: noHtmlLinkForPages,
1373
- [`${name}/no-img-element`]: noImgElement,
1374
- [`${name}/no-page-custom-font`]: noPageCustomFont,
1375
- [`${name}/no-script-component-in-head`]: noScriptComponentInHead,
1376
- [`${name}/no-styled-jsx-in-document`]: noStyledJsxInDocument,
1377
- [`${name}/no-sync-scripts`]: noSyncScripts,
1378
- [`${name}/no-title-in-document-head`]: noTitleInDocumentHead,
1379
- [`${name}/no-typos`]: noTypos,
1380
- [`${name}/no-unwanted-polyfillio`]: noUnwantedPolyfillio
1358
+ "google-font-display": googleFontDisplay,
1359
+ "google-font-preconnect": googleFontPreconnect,
1360
+ "inline-script-id": inlineScriptId,
1361
+ "next-script-for-ga": nextScriptForGa,
1362
+ "no-assign-module-variable": noAssignModuleVariable,
1363
+ "no-async-client-component": noAsyncClientComponent,
1364
+ "no-before-interactive-script-outside-document": noBeforeInteractiveScriptOutsideDocument,
1365
+ "no-css-tags": noCssTags,
1366
+ "no-document-import-in-page": noDocumentImportInPage,
1367
+ "no-duplicate-head": noDuplicateHead,
1368
+ "no-head-element": noHeadElement,
1369
+ "no-head-import-in-document": noHeadImportInDocument,
1370
+ "no-html-link-for-pages": noHtmlLinkForPages,
1371
+ "no-img-element": noImgElement,
1372
+ "no-page-custom-font": noPageCustomFont,
1373
+ "no-script-component-in-head": noScriptComponentInHead,
1374
+ "no-styled-jsx-in-document": noStyledJsxInDocument,
1375
+ "no-sync-scripts": noSyncScripts,
1376
+ "no-title-in-document-head": noTitleInDocumentHead,
1377
+ "no-typos": noTypos,
1378
+ "no-unwanted-polyfillio": noUnwantedPolyfillio
1381
1379
  }
1382
1380
  };
1383
1381
  var recommendedRules = {
1384
1382
  // warnings
1385
- "nextjs/google-font-display": "warn",
1386
- "nextjs/google-font-preconnect": "warn",
1383
+ "google-font-display": "warn",
1384
+ "google-font-preconnect": "warn",
1387
1385
  // errors
1388
- "nextjs/inline-script-id": "error",
1389
- "nextjs/next-script-for-ga": "warn",
1390
- "nextjs/no-assign-module-variable": "error",
1391
- "nextjs/no-async-client-component": "warn",
1392
- "nextjs/no-before-interactive-script-outside-document": "warn",
1393
- "nextjs/no-css-tags": "warn",
1394
- "nextjs/no-document-import-in-page": "error",
1395
- "nextjs/no-duplicate-head": "error",
1396
- "nextjs/no-head-element": "warn",
1397
- "nextjs/no-head-import-in-document": "error",
1398
- "nextjs/no-html-link-for-pages": "warn",
1399
- "nextjs/no-img-element": "warn",
1400
- "nextjs/no-page-custom-font": "warn",
1401
- "nextjs/no-script-component-in-head": "error",
1402
- "nextjs/no-styled-jsx-in-document": "warn",
1403
- "nextjs/no-sync-scripts": "warn",
1404
- "nextjs/no-title-in-document-head": "warn",
1405
- "nextjs/no-typos": "warn",
1406
- "nextjs/no-unwanted-polyfillio": "warn"
1386
+ "inline-script-id": "error",
1387
+ "next-script-for-ga": "warn",
1388
+ "no-assign-module-variable": "error",
1389
+ "no-async-client-component": "warn",
1390
+ "no-before-interactive-script-outside-document": "warn",
1391
+ "no-css-tags": "warn",
1392
+ "no-document-import-in-page": "error",
1393
+ "no-duplicate-head": "error",
1394
+ "no-head-element": "warn",
1395
+ "no-head-import-in-document": "error",
1396
+ "no-html-link-for-pages": "warn",
1397
+ "no-img-element": "warn",
1398
+ "no-page-custom-font": "warn",
1399
+ "no-script-component-in-head": "error",
1400
+ "no-styled-jsx-in-document": "warn",
1401
+ "no-sync-scripts": "warn",
1402
+ "no-title-in-document-head": "warn",
1403
+ "no-typos": "warn",
1404
+ "no-unwanted-polyfillio": "warn"
1407
1405
  };
1408
1406
  var coreWebVitalsRules = {
1409
1407
  ...recommendedRules,
1410
- "nextjs/no-html-link-for-pages": "error",
1411
- "nextjs/no-sync-scripts": "error"
1408
+ "no-html-link-for-pages": "error",
1409
+ "no-sync-scripts": "error"
1412
1410
  };
1413
- var createRuleConfig = (pluginName, rules2, isFlat = false) => {
1411
+ var createRuleConfig = (rules2, isFlat = false) => {
1414
1412
  return {
1415
- plugins: isFlat ? { [pluginName]: plugin } : [pluginName],
1413
+ plugins: isFlat ? { nextjs: plugin } : ["nextjs"],
1416
1414
  rules: rules2
1417
1415
  };
1418
1416
  };
1419
- var recommendedFlatConfig = createRuleConfig(name, recommendedRules, true);
1420
- var recommendedLegacyConfig = createRuleConfig(name, recommendedRules, false);
1421
- var coreWebVitalsFlatConfig = createRuleConfig(
1422
- name,
1423
- coreWebVitalsRules,
1424
- true
1425
- );
1426
- var coreWebVitalsLegacyConfig = createRuleConfig(
1427
- name,
1428
- coreWebVitalsRules,
1429
- false
1430
- );
1417
+ var recommendedFlatConfig = createRuleConfig(recommendedRules, true);
1418
+ var recommendedLegacyConfig = createRuleConfig(recommendedRules, false);
1419
+ var coreWebVitalsFlatConfig = createRuleConfig(coreWebVitalsRules, true);
1420
+ var coreWebVitalsLegacyConfig = createRuleConfig(coreWebVitalsRules, false);
1431
1421
  var index_default = {
1432
1422
  ...plugin,
1433
1423
  configs: {
@@ -1447,7 +1437,8 @@ var index_default = {
1447
1437
  * Flat config (ESLint v9+) with recommended rules
1448
1438
  */
1449
1439
  "recommended/flat": recommendedFlatConfig
1450
- }
1440
+ },
1441
+ name: "nextjs"
1451
1442
  };
1452
1443
  var rules = plugin.rules;
1453
1444
  export {