eslint-plugin-nextjs 0.1.2 → 1.0.1
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 +13 -13
- package/dist/index.d.ts +3 -6
- package/dist/index.js +399 -264
- package/dist/index.js.map +1 -1
- package/package.json +18 -12
- package/dist/index.cjs +0 -1485
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -11
- package/dist/rules/google-font-display.cjs +0 -119
- package/dist/rules/google-font-display.cjs.map +0 -1
- package/dist/rules/google-font-display.d.cts +0 -8
- package/dist/rules/google-font-display.d.ts +0 -8
- package/dist/rules/google-font-display.js +0 -92
- package/dist/rules/google-font-display.js.map +0 -1
- package/dist/rules/google-font-preconnect.cjs +0 -109
- package/dist/rules/google-font-preconnect.cjs.map +0 -1
- package/dist/rules/google-font-preconnect.d.cts +0 -5
- package/dist/rules/google-font-preconnect.d.ts +0 -5
- package/dist/rules/google-font-preconnect.js +0 -82
- package/dist/rules/google-font-preconnect.js.map +0 -1
- package/dist/rules/inline-script-id.cjs +0 -94
- package/dist/rules/inline-script-id.cjs.map +0 -1
- package/dist/rules/inline-script-id.d.cts +0 -5
- package/dist/rules/inline-script-id.d.ts +0 -5
- package/dist/rules/inline-script-id.js +0 -67
- package/dist/rules/inline-script-id.js.map +0 -1
- package/dist/rules/next-script-for-ga.cjs +0 -129
- package/dist/rules/next-script-for-ga.cjs.map +0 -1
- package/dist/rules/next-script-for-ga.d.cts +0 -5
- package/dist/rules/next-script-for-ga.d.ts +0 -5
- package/dist/rules/next-script-for-ga.js +0 -102
- package/dist/rules/next-script-for-ga.js.map +0 -1
- package/dist/rules/no-assign-module-variable.cjs +0 -64
- package/dist/rules/no-assign-module-variable.cjs.map +0 -1
- package/dist/rules/no-assign-module-variable.d.cts +0 -5
- package/dist/rules/no-assign-module-variable.d.ts +0 -5
- package/dist/rules/no-assign-module-variable.js +0 -37
- package/dist/rules/no-assign-module-variable.js.map +0 -1
- package/dist/rules/no-async-client-component.cjs +0 -99
- package/dist/rules/no-async-client-component.cjs.map +0 -1
- package/dist/rules/no-async-client-component.d.cts +0 -5
- package/dist/rules/no-async-client-component.d.ts +0 -5
- package/dist/rules/no-async-client-component.js +0 -72
- package/dist/rules/no-async-client-component.js.map +0 -1
- package/dist/rules/no-before-interactive-script-outside-document.cjs +0 -94
- package/dist/rules/no-before-interactive-script-outside-document.cjs.map +0 -1
- package/dist/rules/no-before-interactive-script-outside-document.d.cts +0 -5
- package/dist/rules/no-before-interactive-script-outside-document.d.ts +0 -5
- package/dist/rules/no-before-interactive-script-outside-document.js +0 -59
- package/dist/rules/no-before-interactive-script-outside-document.js.map +0 -1
- package/dist/rules/no-css-tags.cjs +0 -70
- package/dist/rules/no-css-tags.cjs.map +0 -1
- package/dist/rules/no-css-tags.d.cts +0 -5
- package/dist/rules/no-css-tags.d.ts +0 -5
- package/dist/rules/no-css-tags.js +0 -43
- package/dist/rules/no-css-tags.js.map +0 -1
- package/dist/rules/no-document-import-in-page.cjs +0 -74
- package/dist/rules/no-document-import-in-page.cjs.map +0 -1
- package/dist/rules/no-document-import-in-page.d.cts +0 -5
- package/dist/rules/no-document-import-in-page.d.ts +0 -5
- package/dist/rules/no-document-import-in-page.js +0 -39
- package/dist/rules/no-document-import-in-page.js.map +0 -1
- package/dist/rules/no-duplicate-head.cjs +0 -87
- package/dist/rules/no-duplicate-head.cjs.map +0 -1
- package/dist/rules/no-duplicate-head.d.cts +0 -5
- package/dist/rules/no-duplicate-head.d.ts +0 -5
- package/dist/rules/no-duplicate-head.js +0 -60
- package/dist/rules/no-duplicate-head.js.map +0 -1
- package/dist/rules/no-head-element.cjs +0 -76
- package/dist/rules/no-head-element.cjs.map +0 -1
- package/dist/rules/no-head-element.d.cts +0 -5
- package/dist/rules/no-head-element.d.ts +0 -5
- package/dist/rules/no-head-element.js +0 -41
- package/dist/rules/no-head-element.js.map +0 -1
- package/dist/rules/no-head-import-in-document.cjs +0 -76
- package/dist/rules/no-head-import-in-document.cjs.map +0 -1
- package/dist/rules/no-head-import-in-document.d.cts +0 -5
- package/dist/rules/no-head-import-in-document.d.ts +0 -5
- package/dist/rules/no-head-import-in-document.js +0 -41
- package/dist/rules/no-head-import-in-document.js.map +0 -1
- package/dist/rules/no-html-link-for-pages.cjs +0 -302
- package/dist/rules/no-html-link-for-pages.cjs.map +0 -1
- package/dist/rules/no-html-link-for-pages.d.cts +0 -5
- package/dist/rules/no-html-link-for-pages.d.ts +0 -5
- package/dist/rules/no-html-link-for-pages.js +0 -267
- package/dist/rules/no-html-link-for-pages.js.map +0 -1
- package/dist/rules/no-img-element.cjs +0 -83
- package/dist/rules/no-img-element.cjs.map +0 -1
- package/dist/rules/no-img-element.d.cts +0 -5
- package/dist/rules/no-img-element.d.ts +0 -5
- package/dist/rules/no-img-element.js +0 -48
- package/dist/rules/no-img-element.js.map +0 -1
- package/dist/rules/no-page-custom-font.cjs +0 -184
- package/dist/rules/no-page-custom-font.cjs.map +0 -1
- package/dist/rules/no-page-custom-font.d.cts +0 -5
- package/dist/rules/no-page-custom-font.d.ts +0 -5
- package/dist/rules/no-page-custom-font.js +0 -159
- package/dist/rules/no-page-custom-font.js.map +0 -1
- package/dist/rules/no-script-component-in-head.cjs +0 -74
- package/dist/rules/no-script-component-in-head.cjs.map +0 -1
- package/dist/rules/no-script-component-in-head.d.cts +0 -5
- package/dist/rules/no-script-component-in-head.d.ts +0 -5
- package/dist/rules/no-script-component-in-head.js +0 -47
- package/dist/rules/no-script-component-in-head.js.map +0 -1
- package/dist/rules/no-styled-jsx-in-document.cjs +0 -78
- package/dist/rules/no-styled-jsx-in-document.cjs.map +0 -1
- package/dist/rules/no-styled-jsx-in-document.d.cts +0 -5
- package/dist/rules/no-styled-jsx-in-document.d.ts +0 -5
- package/dist/rules/no-styled-jsx-in-document.js +0 -43
- package/dist/rules/no-styled-jsx-in-document.js.map +0 -1
- package/dist/rules/no-sync-scripts.cjs +0 -64
- package/dist/rules/no-sync-scripts.cjs.map +0 -1
- package/dist/rules/no-sync-scripts.d.cts +0 -5
- package/dist/rules/no-sync-scripts.d.ts +0 -5
- package/dist/rules/no-sync-scripts.js +0 -37
- package/dist/rules/no-sync-scripts.js.map +0 -1
- package/dist/rules/no-title-in-document-head.cjs +0 -78
- package/dist/rules/no-title-in-document-head.cjs.map +0 -1
- package/dist/rules/no-title-in-document-head.d.cts +0 -5
- package/dist/rules/no-title-in-document-head.d.ts +0 -5
- package/dist/rules/no-title-in-document-head.js +0 -51
- package/dist/rules/no-title-in-document-head.js.map +0 -1
- package/dist/rules/no-typos.cjs +0 -133
- package/dist/rules/no-typos.cjs.map +0 -1
- package/dist/rules/no-typos.d.cts +0 -5
- package/dist/rules/no-typos.d.ts +0 -5
- package/dist/rules/no-typos.js +0 -98
- package/dist/rules/no-typos.js.map +0 -1
- package/dist/rules/no-unwanted-polyfillio.cjs +0 -164
- package/dist/rules/no-unwanted-polyfillio.cjs.map +0 -1
- package/dist/rules/no-unwanted-polyfillio.d.cts +0 -5
- package/dist/rules/no-unwanted-polyfillio.d.ts +0 -5
- package/dist/rules/no-unwanted-polyfillio.js +0 -137
- package/dist/rules/no-unwanted-polyfillio.js.map +0 -1
- package/dist/utils/define-rule.cjs +0 -31
- package/dist/utils/define-rule.cjs.map +0 -1
- package/dist/utils/define-rule.d.cts +0 -5
- package/dist/utils/define-rule.d.ts +0 -5
- package/dist/utils/define-rule.js +0 -6
- package/dist/utils/define-rule.js.map +0 -1
- package/dist/utils/get-root-dirs.cjs +0 -60
- package/dist/utils/get-root-dirs.cjs.map +0 -1
- package/dist/utils/get-root-dirs.d.cts +0 -8
- package/dist/utils/get-root-dirs.d.ts +0 -8
- package/dist/utils/get-root-dirs.js +0 -25
- package/dist/utils/get-root-dirs.js.map +0 -1
- package/dist/utils/node-attributes.cjs +0 -67
- package/dist/utils/node-attributes.cjs.map +0 -1
- package/dist/utils/node-attributes.d.cts +0 -15
- package/dist/utils/node-attributes.d.ts +0 -15
- package/dist/utils/node-attributes.js +0 -46
- package/dist/utils/node-attributes.js.map +0 -1
- package/dist/utils/url.cjs +0 -167
- package/dist/utils/url.cjs.map +0 -1
- package/dist/utils/url.d.cts +0 -35
- package/dist/utils/url.d.ts +0 -35
- package/dist/utils/url.js +0 -128
- package/dist/utils/url.js.map +0 -1
@@ -1,83 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __create = Object.create;
|
3
|
-
var __defProp = Object.defineProperty;
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
-
var __export = (target, all) => {
|
9
|
-
for (var name in all)
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
-
};
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
-
for (let key of __getOwnPropNames(from))
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
17
|
-
}
|
18
|
-
return to;
|
19
|
-
};
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
-
mod
|
27
|
-
));
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
|
-
|
30
|
-
// src/rules/no-img-element.ts
|
31
|
-
var no_img_element_exports = {};
|
32
|
-
__export(no_img_element_exports, {
|
33
|
-
noImgElement: () => noImgElement
|
34
|
-
});
|
35
|
-
module.exports = __toCommonJS(no_img_element_exports);
|
36
|
-
var import_node_path = __toESM(require("path"), 1);
|
37
|
-
|
38
|
-
// src/utils/define-rule.ts
|
39
|
-
var defineRule = (rule) => rule;
|
40
|
-
|
41
|
-
// src/rules/no-img-element.ts
|
42
|
-
var url = "https://nextjs.org/docs/messages/no-img-element";
|
43
|
-
var noImgElement = defineRule({
|
44
|
-
create: (context) => {
|
45
|
-
const relativePath = context.filename.replace(import_node_path.default.sep, "/").replace(context.cwd, "").replace(/^\//, "");
|
46
|
-
const isAppDir = /^(?<temp1>src\/)?app\//.test(relativePath);
|
47
|
-
return {
|
48
|
-
JSXOpeningElement: (node) => {
|
49
|
-
if (node.name.name !== "img") {
|
50
|
-
return;
|
51
|
-
}
|
52
|
-
if (node.attributes.length === 0) {
|
53
|
-
return;
|
54
|
-
}
|
55
|
-
if (node.parent?.parent?.openingElement?.name?.name === "picture") {
|
56
|
-
return;
|
57
|
-
}
|
58
|
-
if (isAppDir && /\/opengraph-image|twitter-image|icon\.\w+$/.test(relativePath)) {
|
59
|
-
return;
|
60
|
-
}
|
61
|
-
context.report({
|
62
|
-
message: `Using \`<img>\` could result in slower LCP and higher bandwidth. Consider using \`<Image />\` from \`next/image\` or a custom image loader to automatically optimize images. This may incur additional usage or cost from your provider. See: ${url}`,
|
63
|
-
node
|
64
|
-
});
|
65
|
-
}
|
66
|
-
};
|
67
|
-
},
|
68
|
-
meta: {
|
69
|
-
docs: {
|
70
|
-
category: "HTML",
|
71
|
-
description: "Prevent usage of `<img>` element due to slower LCP and higher bandwidth.",
|
72
|
-
recommended: true,
|
73
|
-
url
|
74
|
-
},
|
75
|
-
schema: [],
|
76
|
-
type: "problem"
|
77
|
-
}
|
78
|
-
});
|
79
|
-
// Annotate the CommonJS export names for ESM import in node:
|
80
|
-
0 && (module.exports = {
|
81
|
-
noImgElement
|
82
|
-
});
|
83
|
-
//# sourceMappingURL=no-img-element.cjs.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../../src/rules/no-img-element.ts","../../src/utils/define-rule.ts"],"sourcesContent":["import path from \"node:path\";\n\nimport { defineRule } from \"../utils/define-rule.js\";\n\nconst url = \"https://nextjs.org/docs/messages/no-img-element\";\n\nexport const noImgElement = defineRule({\n create: (context: any) => {\n // Get relative path of the file\n const relativePath = context.filename\n .replace(path.sep, \"/\")\n .replace(context.cwd, \"\")\n .replace(/^\\//, \"\");\n\n const isAppDir = /^(?<temp1>src\\/)?app\\//.test(relativePath);\n\n return {\n JSXOpeningElement: (node: any) => {\n if (node.name.name !== \"img\") {\n return;\n }\n\n if (node.attributes.length === 0) {\n return;\n }\n\n if (node.parent?.parent?.openingElement?.name?.name === \"picture\") {\n return;\n }\n\n // If is metadata route files, ignore\n // e.g. opengraph-image.js, twitter-image.js, icon.js\n if (\n isAppDir &&\n /\\/opengraph-image|twitter-image|icon\\.\\w+$/.test(relativePath)\n ) {\n return;\n }\n\n context.report({\n message: `Using \\`<img>\\` could result in slower LCP and higher bandwidth. Consider using \\`<Image />\\` from \\`next/image\\` or a custom image loader to automatically optimize images. This may incur additional usage or cost from your provider. See: ${url}`,\n node,\n });\n },\n };\n },\n meta: {\n docs: {\n category: \"HTML\",\n description:\n \"Prevent usage of `<img>` element due to slower LCP and higher bandwidth.\",\n recommended: true,\n url,\n },\n schema: [],\n type: \"problem\",\n },\n});\n","import type { Rule } from \"eslint\";\n\nexport const defineRule = (rule: Rule.RuleModule): Rule.RuleModule => rule;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAiB;;;ACEV,IAAM,aAAa,CAAC,SAA2C;;;ADEtE,IAAM,MAAM;AAEL,IAAM,eAAe,WAAW;AAAA,EACrC,QAAQ,CAAC,YAAiB;AAExB,UAAM,eAAe,QAAQ,SAC1B,QAAQ,iBAAAA,QAAK,KAAK,GAAG,EACrB,QAAQ,QAAQ,KAAK,EAAE,EACvB,QAAQ,OAAO,EAAE;AAEpB,UAAM,WAAW,yBAAyB,KAAK,YAAY;AAE3D,WAAO;AAAA,MACL,mBAAmB,CAAC,SAAc;AAChC,YAAI,KAAK,KAAK,SAAS,OAAO;AAC5B;AAAA,QACF;AAEA,YAAI,KAAK,WAAW,WAAW,GAAG;AAChC;AAAA,QACF;AAEA,YAAI,KAAK,QAAQ,QAAQ,gBAAgB,MAAM,SAAS,WAAW;AACjE;AAAA,QACF;AAIA,YACE,YACA,6CAA6C,KAAK,YAAY,GAC9D;AACA;AAAA,QACF;AAEA,gBAAQ,OAAO;AAAA,UACb,SAAS,iPAAiP,GAAG;AAAA,UAC7P;AAAA,QACF,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AAAA,EACA,MAAM;AAAA,IACJ,MAAM;AAAA,MACJ,UAAU;AAAA,MACV,aACE;AAAA,MACF,aAAa;AAAA,MACb;AAAA,IACF;AAAA,IACA,QAAQ,CAAC;AAAA,IACT,MAAM;AAAA,EACR;AACF,CAAC;","names":["path"]}
|
@@ -1,48 +0,0 @@
|
|
1
|
-
// src/rules/no-img-element.ts
|
2
|
-
import path from "node:path";
|
3
|
-
|
4
|
-
// src/utils/define-rule.ts
|
5
|
-
var defineRule = (rule) => rule;
|
6
|
-
|
7
|
-
// src/rules/no-img-element.ts
|
8
|
-
var url = "https://nextjs.org/docs/messages/no-img-element";
|
9
|
-
var noImgElement = defineRule({
|
10
|
-
create: (context) => {
|
11
|
-
const relativePath = context.filename.replace(path.sep, "/").replace(context.cwd, "").replace(/^\//, "");
|
12
|
-
const isAppDir = /^(?<temp1>src\/)?app\//.test(relativePath);
|
13
|
-
return {
|
14
|
-
JSXOpeningElement: (node) => {
|
15
|
-
if (node.name.name !== "img") {
|
16
|
-
return;
|
17
|
-
}
|
18
|
-
if (node.attributes.length === 0) {
|
19
|
-
return;
|
20
|
-
}
|
21
|
-
if (node.parent?.parent?.openingElement?.name?.name === "picture") {
|
22
|
-
return;
|
23
|
-
}
|
24
|
-
if (isAppDir && /\/opengraph-image|twitter-image|icon\.\w+$/.test(relativePath)) {
|
25
|
-
return;
|
26
|
-
}
|
27
|
-
context.report({
|
28
|
-
message: `Using \`<img>\` could result in slower LCP and higher bandwidth. Consider using \`<Image />\` from \`next/image\` or a custom image loader to automatically optimize images. This may incur additional usage or cost from your provider. See: ${url}`,
|
29
|
-
node
|
30
|
-
});
|
31
|
-
}
|
32
|
-
};
|
33
|
-
},
|
34
|
-
meta: {
|
35
|
-
docs: {
|
36
|
-
category: "HTML",
|
37
|
-
description: "Prevent usage of `<img>` element due to slower LCP and higher bandwidth.",
|
38
|
-
recommended: true,
|
39
|
-
url
|
40
|
-
},
|
41
|
-
schema: [],
|
42
|
-
type: "problem"
|
43
|
-
}
|
44
|
-
});
|
45
|
-
export {
|
46
|
-
noImgElement
|
47
|
-
};
|
48
|
-
//# sourceMappingURL=no-img-element.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../../src/rules/no-img-element.ts","../../src/utils/define-rule.ts"],"sourcesContent":["import path from \"node:path\";\n\nimport { defineRule } from \"../utils/define-rule.js\";\n\nconst url = \"https://nextjs.org/docs/messages/no-img-element\";\n\nexport const noImgElement = defineRule({\n create: (context: any) => {\n // Get relative path of the file\n const relativePath = context.filename\n .replace(path.sep, \"/\")\n .replace(context.cwd, \"\")\n .replace(/^\\//, \"\");\n\n const isAppDir = /^(?<temp1>src\\/)?app\\//.test(relativePath);\n\n return {\n JSXOpeningElement: (node: any) => {\n if (node.name.name !== \"img\") {\n return;\n }\n\n if (node.attributes.length === 0) {\n return;\n }\n\n if (node.parent?.parent?.openingElement?.name?.name === \"picture\") {\n return;\n }\n\n // If is metadata route files, ignore\n // e.g. opengraph-image.js, twitter-image.js, icon.js\n if (\n isAppDir &&\n /\\/opengraph-image|twitter-image|icon\\.\\w+$/.test(relativePath)\n ) {\n return;\n }\n\n context.report({\n message: `Using \\`<img>\\` could result in slower LCP and higher bandwidth. Consider using \\`<Image />\\` from \\`next/image\\` or a custom image loader to automatically optimize images. This may incur additional usage or cost from your provider. See: ${url}`,\n node,\n });\n },\n };\n },\n meta: {\n docs: {\n category: \"HTML\",\n description:\n \"Prevent usage of `<img>` element due to slower LCP and higher bandwidth.\",\n recommended: true,\n url,\n },\n schema: [],\n type: \"problem\",\n },\n});\n","import type { Rule } from \"eslint\";\n\nexport const defineRule = (rule: Rule.RuleModule): Rule.RuleModule => rule;\n"],"mappings":";AAAA,OAAO,UAAU;;;ACEV,IAAM,aAAa,CAAC,SAA2C;;;ADEtE,IAAM,MAAM;AAEL,IAAM,eAAe,WAAW;AAAA,EACrC,QAAQ,CAAC,YAAiB;AAExB,UAAM,eAAe,QAAQ,SAC1B,QAAQ,KAAK,KAAK,GAAG,EACrB,QAAQ,QAAQ,KAAK,EAAE,EACvB,QAAQ,OAAO,EAAE;AAEpB,UAAM,WAAW,yBAAyB,KAAK,YAAY;AAE3D,WAAO;AAAA,MACL,mBAAmB,CAAC,SAAc;AAChC,YAAI,KAAK,KAAK,SAAS,OAAO;AAC5B;AAAA,QACF;AAEA,YAAI,KAAK,WAAW,WAAW,GAAG;AAChC;AAAA,QACF;AAEA,YAAI,KAAK,QAAQ,QAAQ,gBAAgB,MAAM,SAAS,WAAW;AACjE;AAAA,QACF;AAIA,YACE,YACA,6CAA6C,KAAK,YAAY,GAC9D;AACA;AAAA,QACF;AAEA,gBAAQ,OAAO;AAAA,UACb,SAAS,iPAAiP,GAAG;AAAA,UAC7P;AAAA,QACF,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AAAA,EACA,MAAM;AAAA,IACJ,MAAM;AAAA,MACJ,UAAU;AAAA,MACV,aACE;AAAA,MACF,aAAa;AAAA,MACb;AAAA,IACF;AAAA,IACA,QAAQ,CAAC;AAAA,IACT,MAAM;AAAA,EACR;AACF,CAAC;","names":[]}
|
@@ -1,184 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __defProp = Object.defineProperty;
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
-
var __export = (target, all) => {
|
7
|
-
for (var name in all)
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
-
};
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
-
for (let key of __getOwnPropNames(from))
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
-
}
|
16
|
-
return to;
|
17
|
-
};
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
-
|
20
|
-
// src/rules/no-page-custom-font.ts
|
21
|
-
var no_page_custom_font_exports = {};
|
22
|
-
__export(no_page_custom_font_exports, {
|
23
|
-
noPageCustomFont: () => noPageCustomFont
|
24
|
-
});
|
25
|
-
module.exports = __toCommonJS(no_page_custom_font_exports);
|
26
|
-
var import_node_path = require("path");
|
27
|
-
|
28
|
-
// src/utils/define-rule.ts
|
29
|
-
var defineRule = (rule) => rule;
|
30
|
-
|
31
|
-
// src/utils/node-attributes.ts
|
32
|
-
var NodeAttributes = class {
|
33
|
-
attributes;
|
34
|
-
constructor(ASTnode) {
|
35
|
-
this.attributes = {};
|
36
|
-
ASTnode.attributes.forEach((attribute) => {
|
37
|
-
if (!attribute.type || attribute.type !== "JSXAttribute") {
|
38
|
-
return;
|
39
|
-
}
|
40
|
-
if (attribute.value) {
|
41
|
-
const value = typeof attribute.value.value === "string" ? attribute.value.value : typeof attribute.value.expression?.value !== "undefined" ? attribute.value.expression.value : attribute.value.expression?.properties;
|
42
|
-
this.attributes[attribute.name.name] = {
|
43
|
-
hasValue: true,
|
44
|
-
value
|
45
|
-
};
|
46
|
-
} else {
|
47
|
-
this.attributes[attribute.name.name] = {
|
48
|
-
hasValue: false
|
49
|
-
};
|
50
|
-
}
|
51
|
-
});
|
52
|
-
}
|
53
|
-
has(attrName) {
|
54
|
-
return Boolean(this.attributes[attrName]);
|
55
|
-
}
|
56
|
-
hasAny() {
|
57
|
-
return Boolean(Object.keys(this.attributes).length);
|
58
|
-
}
|
59
|
-
hasValue(attrName) {
|
60
|
-
return Boolean(this.attributes[attrName]?.hasValue);
|
61
|
-
}
|
62
|
-
value(attrName) {
|
63
|
-
const attr = this.attributes[attrName];
|
64
|
-
if (!attr) {
|
65
|
-
return true;
|
66
|
-
}
|
67
|
-
if ("hasValue" in attr && attr.hasValue) {
|
68
|
-
return attr.value;
|
69
|
-
}
|
70
|
-
return void 0;
|
71
|
-
}
|
72
|
-
};
|
73
|
-
|
74
|
-
// src/rules/no-page-custom-font.ts
|
75
|
-
var url = "https://nextjs.org/docs/messages/no-page-custom-font";
|
76
|
-
var isIdentifierMatch = (id1, id2) => id1 === null && id2 === null || id1 && id2 && id1.name === id2.name;
|
77
|
-
var noPageCustomFont = defineRule({
|
78
|
-
create: (context) => {
|
79
|
-
const { sourceCode } = context;
|
80
|
-
const paths = context.filename.split("pages");
|
81
|
-
const page = paths[paths.length - 1];
|
82
|
-
if (!page) {
|
83
|
-
return {};
|
84
|
-
}
|
85
|
-
const isDocument = (
|
86
|
-
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
87
|
-
page.startsWith(`${import_node_path.sep}_document`) || page.startsWith(`${import_node_path.posix.sep}_document`)
|
88
|
-
);
|
89
|
-
let documentImportName;
|
90
|
-
let localDefaultExportId;
|
91
|
-
let exportDeclarationType;
|
92
|
-
return {
|
93
|
-
ExportDefaultDeclaration: (node) => {
|
94
|
-
exportDeclarationType = node.declaration.type;
|
95
|
-
if (node.declaration.type === "FunctionDeclaration") {
|
96
|
-
localDefaultExportId = node.declaration.id;
|
97
|
-
return;
|
98
|
-
}
|
99
|
-
if (node.declaration.type === "ClassDeclaration" && node.declaration.superClass && "name" in node.declaration.superClass && node.declaration.superClass.name === documentImportName) {
|
100
|
-
localDefaultExportId = node.declaration.id;
|
101
|
-
}
|
102
|
-
},
|
103
|
-
ImportDeclaration: (node) => {
|
104
|
-
if (node.source.value === "next/document") {
|
105
|
-
const documentImport = node.specifiers.find(
|
106
|
-
({ type }) => type === "ImportDefaultSpecifier"
|
107
|
-
);
|
108
|
-
if (documentImport?.local) {
|
109
|
-
documentImportName = documentImport.local.name;
|
110
|
-
}
|
111
|
-
}
|
112
|
-
},
|
113
|
-
JSXOpeningElement: (node) => {
|
114
|
-
if (node.name.name !== "link") {
|
115
|
-
return;
|
116
|
-
}
|
117
|
-
const ancestors = sourceCode.getAncestors(node);
|
118
|
-
if (!localDefaultExportId) {
|
119
|
-
const program = ancestors.find(
|
120
|
-
(ancestor) => ancestor.type === "Program"
|
121
|
-
);
|
122
|
-
for (let i = 0; i <= program.tokens.length - 1; i++) {
|
123
|
-
if (localDefaultExportId) {
|
124
|
-
break;
|
125
|
-
}
|
126
|
-
const token = program.tokens[i];
|
127
|
-
if (token?.type === "Keyword" && token.value === "export") {
|
128
|
-
const nextToken = program.tokens[i + 1];
|
129
|
-
if (nextToken && nextToken.type === "Keyword" && nextToken.value === "default") {
|
130
|
-
const maybeIdentifier = program.tokens[i + 2];
|
131
|
-
if (maybeIdentifier && maybeIdentifier.type === "Identifier") {
|
132
|
-
localDefaultExportId = { name: maybeIdentifier.value };
|
133
|
-
}
|
134
|
-
}
|
135
|
-
}
|
136
|
-
}
|
137
|
-
}
|
138
|
-
const parentComponent = ancestors.find((ancestor) => {
|
139
|
-
if (exportDeclarationType === "ClassDeclaration") {
|
140
|
-
return ancestor.type === exportDeclarationType && "superClass" in ancestor && ancestor.superClass && "name" in ancestor.superClass && ancestor.superClass.name === documentImportName;
|
141
|
-
}
|
142
|
-
if ("id" in ancestor) {
|
143
|
-
if (exportDeclarationType === "FunctionDeclaration") {
|
144
|
-
return ancestor.type === exportDeclarationType && isIdentifierMatch(ancestor.id, localDefaultExportId);
|
145
|
-
}
|
146
|
-
return isIdentifierMatch(ancestor.id, localDefaultExportId);
|
147
|
-
}
|
148
|
-
return false;
|
149
|
-
});
|
150
|
-
if (isDocument && parentComponent) {
|
151
|
-
return;
|
152
|
-
}
|
153
|
-
const attributes = new NodeAttributes(node);
|
154
|
-
if (!attributes.has("href") || !attributes.hasValue("href")) {
|
155
|
-
return;
|
156
|
-
}
|
157
|
-
const hrefValue = attributes.value("href");
|
158
|
-
const isGoogleFont = typeof hrefValue === "string" && hrefValue.startsWith("https://fonts.googleapis.com/css");
|
159
|
-
if (isGoogleFont) {
|
160
|
-
const end = `This is discouraged. See: ${url}`;
|
161
|
-
const message = isDocument ? `Using \`<link />\` outside of \`<Head>\` will disable automatic font optimization. ${end}` : `Custom fonts not added in \`pages/_document.js\` will only load for a single page. ${end}`;
|
162
|
-
context.report({
|
163
|
-
message,
|
164
|
-
node
|
165
|
-
});
|
166
|
-
}
|
167
|
-
}
|
168
|
-
};
|
169
|
-
},
|
170
|
-
meta: {
|
171
|
-
docs: {
|
172
|
-
description: "Prevent page-only custom fonts.",
|
173
|
-
recommended: true,
|
174
|
-
url
|
175
|
-
},
|
176
|
-
schema: [],
|
177
|
-
type: "problem"
|
178
|
-
}
|
179
|
-
});
|
180
|
-
// Annotate the CommonJS export names for ESM import in node:
|
181
|
-
0 && (module.exports = {
|
182
|
-
noPageCustomFont
|
183
|
-
});
|
184
|
-
//# sourceMappingURL=no-page-custom-font.cjs.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../../src/rules/no-page-custom-font.ts","../../src/utils/define-rule.ts","../../src/utils/node-attributes.ts"],"sourcesContent":["import type { AST } from \"eslint\";\n\nimport { posix, sep } from \"node:path\";\n\nimport { defineRule } from \"../utils/define-rule.js\";\nimport NodeAttributes from \"../utils/node-attributes.js\";\n\nconst url = \"https://nextjs.org/docs/messages/no-page-custom-font\";\n\nconst isIdentifierMatch = (id1: any, id2: any): boolean =>\n (id1 === null && id2 === null) || (id1 && id2 && id1.name === id2.name);\n\nexport const noPageCustomFont = defineRule({\n create: (context: any): any => {\n const { sourceCode } = context;\n const paths = context.filename.split(\"pages\");\n const page = paths[paths.length - 1];\n\n // outside of a file within `pages`, bail\n if (!page) {\n return {};\n }\n\n const isDocument =\n // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n page.startsWith(`${sep}_document`) ||\n page.startsWith(`${posix.sep}_document`);\n\n let documentImportName: string | undefined;\n let localDefaultExportId: any;\n let exportDeclarationType: string | undefined;\n\n return {\n ExportDefaultDeclaration: (node: any): void => {\n exportDeclarationType = node.declaration.type;\n\n if (node.declaration.type === \"FunctionDeclaration\") {\n localDefaultExportId = node.declaration.id;\n return;\n }\n\n if (\n node.declaration.type === \"ClassDeclaration\" &&\n node.declaration.superClass &&\n \"name\" in node.declaration.superClass &&\n node.declaration.superClass.name === documentImportName\n ) {\n localDefaultExportId = node.declaration.id;\n }\n },\n\n ImportDeclaration: (node: any): void => {\n if (node.source.value === \"next/document\") {\n const documentImport = node.specifiers.find(\n ({ type }: { type: string }) => type === \"ImportDefaultSpecifier\",\n );\n if (documentImport?.local) {\n documentImportName = documentImport.local.name;\n }\n }\n },\n\n JSXOpeningElement: (node: any): void => {\n if (node.name.name !== \"link\") {\n return;\n }\n\n const ancestors = sourceCode.getAncestors(node);\n\n // if `export default <n>` is further down within the file after the\n // currently traversed component, then `localDefaultExportName` will\n // still be undefined\n if (!localDefaultExportId) {\n // find the top level of the module\n const program = ancestors.find(\n (ancestor: any) => ancestor.type === \"Program\",\n ) as AST.Program;\n\n // go over each token to find the combination of `export default <n>`\n for (let i = 0; i <= program.tokens.length - 1; i++) {\n if (localDefaultExportId) {\n break;\n }\n\n const token = program.tokens[i];\n\n if (token?.type === \"Keyword\" && token.value === \"export\") {\n const nextToken = program.tokens[i + 1];\n\n if (\n nextToken &&\n nextToken.type === \"Keyword\" &&\n nextToken.value === \"default\"\n ) {\n const maybeIdentifier = program.tokens[i + 2];\n\n if (maybeIdentifier && maybeIdentifier.type === \"Identifier\") {\n localDefaultExportId = { name: maybeIdentifier.value };\n }\n }\n }\n }\n }\n\n const parentComponent = ancestors.find((ancestor: any) => {\n // export default class ... extends ...\n if (exportDeclarationType === \"ClassDeclaration\") {\n return (\n ancestor.type === exportDeclarationType &&\n \"superClass\" in ancestor &&\n ancestor.superClass &&\n \"name\" in ancestor.superClass &&\n ancestor.superClass.name === documentImportName\n );\n }\n\n if (\"id\" in ancestor) {\n // export default function ...\n if (exportDeclarationType === \"FunctionDeclaration\") {\n return (\n ancestor.type === exportDeclarationType &&\n isIdentifierMatch(ancestor.id, localDefaultExportId)\n );\n }\n\n // function ...() {} export default ...\n // class ... extends ...; export default ...\n return isIdentifierMatch(ancestor.id, localDefaultExportId);\n }\n\n return false;\n });\n\n // file starts with _document and this <link /> is within the default export\n if (isDocument && parentComponent) {\n return;\n }\n\n const attributes = new NodeAttributes(node);\n if (!attributes.has(\"href\") || !attributes.hasValue(\"href\")) {\n return;\n }\n\n const hrefValue = attributes.value(\"href\");\n const isGoogleFont =\n typeof hrefValue === \"string\" &&\n hrefValue.startsWith(\"https://fonts.googleapis.com/css\");\n\n if (isGoogleFont) {\n const end = `This is discouraged. See: ${url}`;\n\n const message =\n isDocument ?\n `Using \\`<link />\\` outside of \\`<Head>\\` will disable automatic font optimization. ${end}`\n : `Custom fonts not added in \\`pages/_document.js\\` will only load for a single page. ${end}`;\n\n context.report({\n message,\n node,\n });\n }\n },\n };\n },\n meta: {\n docs: {\n description: \"Prevent page-only custom fonts.\",\n recommended: true,\n url,\n },\n schema: [],\n type: \"problem\",\n },\n});\n","import type { Rule } from \"eslint\";\n\nexport const defineRule = (rule: Rule.RuleModule): Rule.RuleModule => rule;\n","// Return attributes and values of a node in a convenient way:\n/* example: \n <ExampleElement attr1=\"15\" attr2>\n { attr1: {\n hasValue: true,\n value: 15\n },\n attr2: {\n hasValue: false\n }\nInclusion of hasValue is in case an eslint rule cares about boolean values\nexplicitly assigned to attribute vs the attribute being used as a flag\n*/\nexport default class NodeAttributes {\n attributes: Record<\n string,\n | {\n hasValue: true;\n value: any;\n }\n | {\n hasValue?: false;\n }\n >;\n\n constructor(ASTnode: any) {\n this.attributes = {};\n ASTnode.attributes.forEach((attribute: any) => {\n if (!attribute.type || attribute.type !== \"JSXAttribute\") {\n return;\n }\n\n if (attribute.value) {\n // hasValue\n const value =\n typeof attribute.value.value === \"string\" ? attribute.value.value\n : typeof attribute.value.expression?.value !== \"undefined\" ?\n attribute.value.expression.value\n : attribute.value.expression?.properties;\n\n this.attributes[attribute.name.name] = {\n hasValue: true,\n value,\n };\n } else {\n this.attributes[attribute.name.name] = {\n hasValue: false,\n };\n }\n });\n }\n\n has(attrName: string): boolean {\n return Boolean(this.attributes[attrName]);\n }\n\n hasAny(): boolean {\n return Boolean(Object.keys(this.attributes).length);\n }\n\n hasValue(attrName: string): boolean {\n return Boolean(this.attributes[attrName]?.hasValue);\n }\n\n value(attrName: string): any {\n const attr = this.attributes[attrName];\n\n if (!attr) {\n return true;\n }\n\n if (\"hasValue\" in attr && attr.hasValue) {\n return attr.value;\n }\n\n return undefined;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,uBAA2B;;;ACApB,IAAM,aAAa,CAAC,SAA2C;;;ACWtE,IAAqB,iBAArB,MAAoC;AAAA,EAClC;AAAA,EAWA,YAAY,SAAc;AACxB,SAAK,aAAa,CAAC;AACnB,YAAQ,WAAW,QAAQ,CAAC,cAAmB;AAC7C,UAAI,CAAC,UAAU,QAAQ,UAAU,SAAS,gBAAgB;AACxD;AAAA,MACF;AAEA,UAAI,UAAU,OAAO;AAEnB,cAAM,QACJ,OAAO,UAAU,MAAM,UAAU,WAAW,UAAU,MAAM,QAC1D,OAAO,UAAU,MAAM,YAAY,UA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ACF;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAEA,cAAM,kBAAkB,UAAU,KAAK,CAAC,aAAkB;AAExD,cAAI,0BAA0B,oBAAoB;AAChD,mBACE,SAAS,SAAS,yBAClB,gBAAgB,YAChB,SAAS,cACT,UAAU,SAAS,cACnB,SAAS,WAAW,SAAS;AAAA,UAEjC;AAEA,cAAI,QAAQ,UAAU;AAEpB,gBAAI,0BAA0B,uBAAuB;AACnD,qBACE,SAAS,SAAS,yBAClB,kBAAkB,SAAS,IAAI,oBAAoB;AAAA,YAEvD;AAIA,mBAAO,kBAAkB,SAAS,IAAI,oBAAoB;AAAA,UAC5D;AAEA,iBAAO;AAAA,QACT,CAAC;AAGD,YAAI,cAAc,iBAAiB;AACjC;AAAA,QACF;AAEA,cAAM,aAAa,IAAI,eAAe,IAAI;AAC1C,YAAI,CAAC,WAAW,IAAI,MAAM,KAAK,CAAC,WAAW,SAAS,MAAM,GAAG;AAC3D;AAAA,QACF;AAEA,cAAM,YAAY,WAAW,MAAM,MAAM;AACzC,cAAM,eACJ,OAAO,cAAc,YACrB,UAAU,WAAW,kCAAkC;AAEzD,YAAI,cAAc;AAChB,gBAAM,MAAM,6BAA6B,GAAG;AAE5C,gBAAM,UACJ,aACE,sFAAsF,GAAG,KACzF,sFAAsF,GAAG;AAE7F,kBAAQ,OAAO;AAAA,YACb;AAAA,YACA;AAAA,UACF,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EACA,MAAM;AAAA,IACJ,MAAM;AAAA,MACJ,aAAa;AAAA,MACb,aAAa;AAAA,MACb;AAAA,IACF;AAAA,IACA,QAAQ,CAAC;AAAA,IACT,MAAM;AAAA,EACR;AACF,CAAC;","names":[]}
|
@@ -1,159 +0,0 @@
|
|
1
|
-
// src/rules/no-page-custom-font.ts
|
2
|
-
import { posix, sep } from "node:path";
|
3
|
-
|
4
|
-
// src/utils/define-rule.ts
|
5
|
-
var defineRule = (rule) => rule;
|
6
|
-
|
7
|
-
// src/utils/node-attributes.ts
|
8
|
-
var NodeAttributes = class {
|
9
|
-
attributes;
|
10
|
-
constructor(ASTnode) {
|
11
|
-
this.attributes = {};
|
12
|
-
ASTnode.attributes.forEach((attribute) => {
|
13
|
-
if (!attribute.type || attribute.type !== "JSXAttribute") {
|
14
|
-
return;
|
15
|
-
}
|
16
|
-
if (attribute.value) {
|
17
|
-
const value = typeof attribute.value.value === "string" ? attribute.value.value : typeof attribute.value.expression?.value !== "undefined" ? attribute.value.expression.value : attribute.value.expression?.properties;
|
18
|
-
this.attributes[attribute.name.name] = {
|
19
|
-
hasValue: true,
|
20
|
-
value
|
21
|
-
};
|
22
|
-
} else {
|
23
|
-
this.attributes[attribute.name.name] = {
|
24
|
-
hasValue: false
|
25
|
-
};
|
26
|
-
}
|
27
|
-
});
|
28
|
-
}
|
29
|
-
has(attrName) {
|
30
|
-
return Boolean(this.attributes[attrName]);
|
31
|
-
}
|
32
|
-
hasAny() {
|
33
|
-
return Boolean(Object.keys(this.attributes).length);
|
34
|
-
}
|
35
|
-
hasValue(attrName) {
|
36
|
-
return Boolean(this.attributes[attrName]?.hasValue);
|
37
|
-
}
|
38
|
-
value(attrName) {
|
39
|
-
const attr = this.attributes[attrName];
|
40
|
-
if (!attr) {
|
41
|
-
return true;
|
42
|
-
}
|
43
|
-
if ("hasValue" in attr && attr.hasValue) {
|
44
|
-
return attr.value;
|
45
|
-
}
|
46
|
-
return void 0;
|
47
|
-
}
|
48
|
-
};
|
49
|
-
|
50
|
-
// src/rules/no-page-custom-font.ts
|
51
|
-
var url = "https://nextjs.org/docs/messages/no-page-custom-font";
|
52
|
-
var isIdentifierMatch = (id1, id2) => id1 === null && id2 === null || id1 && id2 && id1.name === id2.name;
|
53
|
-
var noPageCustomFont = defineRule({
|
54
|
-
create: (context) => {
|
55
|
-
const { sourceCode } = context;
|
56
|
-
const paths = context.filename.split("pages");
|
57
|
-
const page = paths[paths.length - 1];
|
58
|
-
if (!page) {
|
59
|
-
return {};
|
60
|
-
}
|
61
|
-
const isDocument = (
|
62
|
-
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
63
|
-
page.startsWith(`${sep}_document`) || page.startsWith(`${posix.sep}_document`)
|
64
|
-
);
|
65
|
-
let documentImportName;
|
66
|
-
let localDefaultExportId;
|
67
|
-
let exportDeclarationType;
|
68
|
-
return {
|
69
|
-
ExportDefaultDeclaration: (node) => {
|
70
|
-
exportDeclarationType = node.declaration.type;
|
71
|
-
if (node.declaration.type === "FunctionDeclaration") {
|
72
|
-
localDefaultExportId = node.declaration.id;
|
73
|
-
return;
|
74
|
-
}
|
75
|
-
if (node.declaration.type === "ClassDeclaration" && node.declaration.superClass && "name" in node.declaration.superClass && node.declaration.superClass.name === documentImportName) {
|
76
|
-
localDefaultExportId = node.declaration.id;
|
77
|
-
}
|
78
|
-
},
|
79
|
-
ImportDeclaration: (node) => {
|
80
|
-
if (node.source.value === "next/document") {
|
81
|
-
const documentImport = node.specifiers.find(
|
82
|
-
({ type }) => type === "ImportDefaultSpecifier"
|
83
|
-
);
|
84
|
-
if (documentImport?.local) {
|
85
|
-
documentImportName = documentImport.local.name;
|
86
|
-
}
|
87
|
-
}
|
88
|
-
},
|
89
|
-
JSXOpeningElement: (node) => {
|
90
|
-
if (node.name.name !== "link") {
|
91
|
-
return;
|
92
|
-
}
|
93
|
-
const ancestors = sourceCode.getAncestors(node);
|
94
|
-
if (!localDefaultExportId) {
|
95
|
-
const program = ancestors.find(
|
96
|
-
(ancestor) => ancestor.type === "Program"
|
97
|
-
);
|
98
|
-
for (let i = 0; i <= program.tokens.length - 1; i++) {
|
99
|
-
if (localDefaultExportId) {
|
100
|
-
break;
|
101
|
-
}
|
102
|
-
const token = program.tokens[i];
|
103
|
-
if (token?.type === "Keyword" && token.value === "export") {
|
104
|
-
const nextToken = program.tokens[i + 1];
|
105
|
-
if (nextToken && nextToken.type === "Keyword" && nextToken.value === "default") {
|
106
|
-
const maybeIdentifier = program.tokens[i + 2];
|
107
|
-
if (maybeIdentifier && maybeIdentifier.type === "Identifier") {
|
108
|
-
localDefaultExportId = { name: maybeIdentifier.value };
|
109
|
-
}
|
110
|
-
}
|
111
|
-
}
|
112
|
-
}
|
113
|
-
}
|
114
|
-
const parentComponent = ancestors.find((ancestor) => {
|
115
|
-
if (exportDeclarationType === "ClassDeclaration") {
|
116
|
-
return ancestor.type === exportDeclarationType && "superClass" in ancestor && ancestor.superClass && "name" in ancestor.superClass && ancestor.superClass.name === documentImportName;
|
117
|
-
}
|
118
|
-
if ("id" in ancestor) {
|
119
|
-
if (exportDeclarationType === "FunctionDeclaration") {
|
120
|
-
return ancestor.type === exportDeclarationType && isIdentifierMatch(ancestor.id, localDefaultExportId);
|
121
|
-
}
|
122
|
-
return isIdentifierMatch(ancestor.id, localDefaultExportId);
|
123
|
-
}
|
124
|
-
return false;
|
125
|
-
});
|
126
|
-
if (isDocument && parentComponent) {
|
127
|
-
return;
|
128
|
-
}
|
129
|
-
const attributes = new NodeAttributes(node);
|
130
|
-
if (!attributes.has("href") || !attributes.hasValue("href")) {
|
131
|
-
return;
|
132
|
-
}
|
133
|
-
const hrefValue = attributes.value("href");
|
134
|
-
const isGoogleFont = typeof hrefValue === "string" && hrefValue.startsWith("https://fonts.googleapis.com/css");
|
135
|
-
if (isGoogleFont) {
|
136
|
-
const end = `This is discouraged. See: ${url}`;
|
137
|
-
const message = isDocument ? `Using \`<link />\` outside of \`<Head>\` will disable automatic font optimization. ${end}` : `Custom fonts not added in \`pages/_document.js\` will only load for a single page. ${end}`;
|
138
|
-
context.report({
|
139
|
-
message,
|
140
|
-
node
|
141
|
-
});
|
142
|
-
}
|
143
|
-
}
|
144
|
-
};
|
145
|
-
},
|
146
|
-
meta: {
|
147
|
-
docs: {
|
148
|
-
description: "Prevent page-only custom fonts.",
|
149
|
-
recommended: true,
|
150
|
-
url
|
151
|
-
},
|
152
|
-
schema: [],
|
153
|
-
type: "problem"
|
154
|
-
}
|
155
|
-
});
|
156
|
-
export {
|
157
|
-
noPageCustomFont
|
158
|
-
};
|
159
|
-
//# sourceMappingURL=no-page-custom-font.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../../src/rules/no-page-custom-font.ts","../../src/utils/define-rule.ts","../../src/utils/node-attributes.ts"],"sourcesContent":["import type { AST } from \"eslint\";\n\nimport { posix, sep } from \"node:path\";\n\nimport { defineRule } from \"../utils/define-rule.js\";\nimport NodeAttributes from \"../utils/node-attributes.js\";\n\nconst url = \"https://nextjs.org/docs/messages/no-page-custom-font\";\n\nconst isIdentifierMatch = (id1: any, id2: any): boolean =>\n (id1 === null && id2 === null) || (id1 && id2 && id1.name === id2.name);\n\nexport const noPageCustomFont = defineRule({\n create: (context: any): any => {\n const { sourceCode } = context;\n const paths = context.filename.split(\"pages\");\n const page = paths[paths.length - 1];\n\n // outside of a file within `pages`, bail\n if (!page) {\n return {};\n }\n\n const isDocument =\n // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n page.startsWith(`${sep}_document`) ||\n page.startsWith(`${posix.sep}_document`);\n\n let documentImportName: string | undefined;\n let localDefaultExportId: any;\n let exportDeclarationType: string | undefined;\n\n return {\n ExportDefaultDeclaration: (node: any): void => {\n exportDeclarationType = node.declaration.type;\n\n if (node.declaration.type === \"FunctionDeclaration\") {\n localDefaultExportId = node.declaration.id;\n return;\n }\n\n if (\n node.declaration.type === \"ClassDeclaration\" &&\n node.declaration.superClass &&\n \"name\" in node.declaration.superClass &&\n node.declaration.superClass.name === documentImportName\n ) {\n localDefaultExportId = node.declaration.id;\n }\n },\n\n ImportDeclaration: (node: any): void => {\n if (node.source.value === \"next/document\") {\n const documentImport = node.specifiers.find(\n ({ type }: { type: string }) => type === \"ImportDefaultSpecifier\",\n );\n if (documentImport?.local) {\n documentImportName = documentImport.local.name;\n }\n }\n },\n\n JSXOpeningElement: (node: any): void => {\n if (node.name.name !== \"link\") {\n return;\n }\n\n const ancestors = sourceCode.getAncestors(node);\n\n // if `export default <n>` is further down within the file after the\n // currently traversed component, then `localDefaultExportName` will\n // still be undefined\n if (!localDefaultExportId) {\n // find the top level of the module\n const program = ancestors.find(\n (ancestor: any) => ancestor.type === \"Program\",\n ) as AST.Program;\n\n // go over each token to find the combination of `export default <n>`\n for (let i = 0; i <= program.tokens.length - 1; i++) {\n if (localDefaultExportId) {\n break;\n }\n\n const token = program.tokens[i];\n\n if (token?.type === \"Keyword\" && token.value === \"export\") {\n const nextToken = program.tokens[i + 1];\n\n if (\n nextToken &&\n nextToken.type === \"Keyword\" &&\n nextToken.value === \"default\"\n ) {\n const maybeIdentifier = program.tokens[i + 2];\n\n if (maybeIdentifier && maybeIdentifier.type === \"Identifier\") {\n localDefaultExportId = { name: maybeIdentifier.value };\n }\n }\n }\n }\n }\n\n const parentComponent = ancestors.find((ancestor: any) => {\n // export default class ... extends ...\n if (exportDeclarationType === \"ClassDeclaration\") {\n return (\n ancestor.type === exportDeclarationType &&\n \"superClass\" in ancestor &&\n ancestor.superClass &&\n \"name\" in ancestor.superClass &&\n ancestor.superClass.name === documentImportName\n );\n }\n\n if (\"id\" in ancestor) {\n // export default function ...\n if (exportDeclarationType === \"FunctionDeclaration\") {\n return (\n ancestor.type === exportDeclarationType &&\n isIdentifierMatch(ancestor.id, localDefaultExportId)\n );\n }\n\n // function ...() {} export default ...\n // class ... extends ...; export default ...\n return isIdentifierMatch(ancestor.id, localDefaultExportId);\n }\n\n return false;\n });\n\n // file starts with _document and this <link /> is within the default export\n if (isDocument && parentComponent) {\n return;\n }\n\n const attributes = new NodeAttributes(node);\n if (!attributes.has(\"href\") || !attributes.hasValue(\"href\")) {\n return;\n }\n\n const hrefValue = attributes.value(\"href\");\n const isGoogleFont =\n typeof hrefValue === \"string\" &&\n hrefValue.startsWith(\"https://fonts.googleapis.com/css\");\n\n if (isGoogleFont) {\n const end = `This is discouraged. See: ${url}`;\n\n const message =\n isDocument ?\n `Using \\`<link />\\` outside of \\`<Head>\\` will disable automatic font optimization. ${end}`\n : `Custom fonts not added in \\`pages/_document.js\\` will only load for a single page. ${end}`;\n\n context.report({\n message,\n node,\n });\n }\n },\n };\n },\n meta: {\n docs: {\n description: \"Prevent page-only custom fonts.\",\n recommended: true,\n url,\n },\n schema: [],\n type: \"problem\",\n },\n});\n","import type { Rule } from \"eslint\";\n\nexport const defineRule = (rule: Rule.RuleModule): Rule.RuleModule => rule;\n","// Return attributes and values of a node in a convenient way:\n/* example: \n <ExampleElement attr1=\"15\" attr2>\n { attr1: {\n hasValue: true,\n value: 15\n },\n attr2: {\n hasValue: false\n }\nInclusion of hasValue is in case an eslint rule cares about boolean values\nexplicitly assigned to attribute vs the attribute being used as a flag\n*/\nexport default class NodeAttributes {\n attributes: Record<\n string,\n | {\n hasValue: true;\n value: any;\n }\n | {\n hasValue?: false;\n }\n >;\n\n constructor(ASTnode: any) {\n this.attributes = {};\n ASTnode.attributes.forEach((attribute: any) => {\n if (!attribute.type || attribute.type !== \"JSXAttribute\") {\n return;\n }\n\n if (attribute.value) {\n // hasValue\n const value =\n typeof attribute.value.value === \"string\" ? attribute.value.value\n : typeof attribute.value.expression?.value !== \"undefined\" ?\n attribute.value.expression.value\n : attribute.value.expression?.properties;\n\n this.attributes[attribute.name.name] = {\n hasValue: true,\n value,\n };\n } else {\n this.attributes[attribute.name.name] = {\n hasValue: false,\n };\n }\n });\n }\n\n has(attrName: string): boolean {\n return Boolean(this.attributes[attrName]);\n }\n\n hasAny(): boolean {\n return Boolean(Object.keys(this.attributes).length);\n }\n\n hasValue(attrName: string): boolean {\n return Boolean(this.attributes[attrName]?.hasValue);\n }\n\n value(attrName: string): any {\n const attr = this.attributes[attrName];\n\n if (!attr) {\n return true;\n }\n\n if (\"hasValue\" in attr && attr.hasValue) {\n return attr.value;\n }\n\n return undefined;\n }\n}\n"],"mappings":";AAEA,SAAS,OAAO,WAAW;;;ACApB,IAAM,aAAa,CAAC,SAA2C;;;ACWtE,IAAqB,iBAArB,MAAoC;AAAA,EAClC;AAAA,EAWA,YAAY,S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AAa;AAAA,MACb;AAAA,IACF;AAAA,IACA,QAAQ,CAAC;AAAA,IACT,MAAM;AAAA,EACR;AACF,CAAC;","names":[]}
|
@@ -1,74 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __defProp = Object.defineProperty;
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
-
var __export = (target, all) => {
|
7
|
-
for (var name in all)
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
-
};
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
-
for (let key of __getOwnPropNames(from))
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
-
}
|
16
|
-
return to;
|
17
|
-
};
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
-
|
20
|
-
// src/rules/no-script-component-in-head.ts
|
21
|
-
var no_script_component_in_head_exports = {};
|
22
|
-
__export(no_script_component_in_head_exports, {
|
23
|
-
noScriptComponentInHead: () => noScriptComponentInHead
|
24
|
-
});
|
25
|
-
module.exports = __toCommonJS(no_script_component_in_head_exports);
|
26
|
-
|
27
|
-
// src/utils/define-rule.ts
|
28
|
-
var defineRule = (rule) => rule;
|
29
|
-
|
30
|
-
// src/rules/no-script-component-in-head.ts
|
31
|
-
var url = "https://nextjs.org/docs/messages/no-script-component-in-head";
|
32
|
-
var noScriptComponentInHead = defineRule({
|
33
|
-
create: (context) => {
|
34
|
-
let isNextHead = null;
|
35
|
-
return {
|
36
|
-
ImportDeclaration: (node) => {
|
37
|
-
if (node.source.value === "next/head") {
|
38
|
-
isNextHead = node.source.value;
|
39
|
-
}
|
40
|
-
},
|
41
|
-
JSXElement: (node) => {
|
42
|
-
if (!isNextHead) {
|
43
|
-
return;
|
44
|
-
}
|
45
|
-
if (node.openingElement?.name && node.openingElement.name.name !== "Head") {
|
46
|
-
return;
|
47
|
-
}
|
48
|
-
const scriptTag = node.children.find(
|
49
|
-
(child) => child.openingElement?.name && child.openingElement.name.name === "Script"
|
50
|
-
);
|
51
|
-
if (scriptTag) {
|
52
|
-
context.report({
|
53
|
-
message: `\`next/script\` should not be used in \`next/head\` component. Move \`<Script />\` outside of \`<Head>\` instead. See: ${url}`,
|
54
|
-
node
|
55
|
-
});
|
56
|
-
}
|
57
|
-
}
|
58
|
-
};
|
59
|
-
},
|
60
|
-
meta: {
|
61
|
-
docs: {
|
62
|
-
description: "Prevent usage of `next/script` in `next/head` component.",
|
63
|
-
recommended: true,
|
64
|
-
url
|
65
|
-
},
|
66
|
-
schema: [],
|
67
|
-
type: "problem"
|
68
|
-
}
|
69
|
-
});
|
70
|
-
// Annotate the CommonJS export names for ESM import in node:
|
71
|
-
0 && (module.exports = {
|
72
|
-
noScriptComponentInHead
|
73
|
-
});
|
74
|
-
//# sourceMappingURL=no-script-component-in-head.cjs.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../../src/rules/no-script-component-in-head.ts","../../src/utils/define-rule.ts"],"sourcesContent":["import { defineRule } from \"../utils/define-rule.js\";\nconst url = \"https://nextjs.org/docs/messages/no-script-component-in-head\";\n\nexport const noScriptComponentInHead = defineRule({\n create: (context: any) => {\n let isNextHead: null | string = null;\n\n return {\n ImportDeclaration: (node: any) => {\n if (node.source.value === \"next/head\") {\n isNextHead = node.source.value;\n }\n },\n JSXElement: (node: any) => {\n if (!isNextHead) {\n return;\n }\n\n if (\n node.openingElement?.name &&\n node.openingElement.name.name !== \"Head\"\n ) {\n return;\n }\n\n const scriptTag = node.children.find(\n (child: any) =>\n child.openingElement?.name &&\n child.openingElement.name.name === \"Script\",\n );\n\n if (scriptTag) {\n context.report({\n message: `\\`next/script\\` should not be used in \\`next/head\\` component. Move \\`<Script />\\` outside of \\`<Head>\\` instead. See: ${url}`,\n node,\n });\n }\n },\n };\n },\n meta: {\n docs: {\n description: \"Prevent usage of `next/script` in `next/head` component.\",\n recommended: true,\n url,\n },\n schema: [],\n type: \"problem\",\n },\n});\n","import type { Rule } from \"eslint\";\n\nexport const defineRule = (rule: Rule.RuleModule): Rule.RuleModule => rule;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,IAAM,aAAa,CAAC,SAA2C;;;ADDtE,IAAM,MAAM;AAEL,IAAM,0BAA0B,WAAW;AAAA,EAChD,QAAQ,CAAC,YAAiB;AACxB,QAAI,aAA4B;AAEhC,WAAO;AAAA,MACL,mBAAmB,CAAC,SAAc;AAChC,YAAI,KAAK,OAAO,UAAU,aAAa;AACrC,uBAAa,KAAK,OAAO;AAAA,QAC3B;AAAA,MACF;AAAA,MACA,YAAY,CAAC,SAAc;AACzB,YAAI,CAAC,YAAY;AACf;AAAA,QACF;AAEA,YACE,KAAK,gBAAgB,QACrB,KAAK,eAAe,KAAK,SAAS,QAClC;AACA;AAAA,QACF;AAEA,cAAM,YAAY,KAAK,SAAS;AAAA,UAC9B,CAAC,UACC,MAAM,gBAAgB,QACtB,MAAM,eAAe,KAAK,SAAS;AAAA,QACvC;AAEA,YAAI,WAAW;AACb,kBAAQ,OAAO;AAAA,YACb,SAAS,0HAA0H,GAAG;AAAA,YACtI;AAAA,UACF,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EACA,MAAM;AAAA,IACJ,MAAM;AAAA,MACJ,aAAa;AAAA,MACb,aAAa;AAAA,MACb;AAAA,IACF;AAAA,IACA,QAAQ,CAAC;AAAA,IACT,MAAM;AAAA,EACR;AACF,CAAC;","names":[]}
|