eslint-plugin-nextjs 0.1.1 → 1.0.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 +13 -13
- package/dist/index.d.ts +4 -39
- package/dist/index.js +403 -274
- package/dist/index.js.map +1 -1
- package/package.json +15 -10
- package/dist/index.cjs +0 -1494
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -43
- 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 +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":";;;;;;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BAAQ,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,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,UAAU,cAC7C,UAAU,MAAM,WAAW,QAC3B,UAAU,MAAM,YAAY;AAEhC,aAAK,WAAW,UAAU,KAAK,IAAI,IAAI;AAAA,UACrC,UAAU;AAAA,UACV;AAAA,QACF;AAAA,MACF,OAAO;AACL,aAAK,WAAW,UAAU,KAAK,IAAI,IAAI;AAAA,UACrC,UAAU;AAAA,QACZ;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEA,IAAI,UAA2B;AAC7B,WAAO,QAAQ,KAAK,WAAW,QAAQ,CAAC;AAAA,EAC1C;AAAA,EAEA,SAAkB;AAChB,WAAO,QAAQ,OAAO,KAAK,KAAK,UAAU,EAAE,MAAM;AAAA,EACpD;AAAA,EAEA,SAAS,UAA2B;AAClC,WAAO,QAAQ,KAAK,WAAW,QAAQ,GAAG,QAAQ;AAAA,EACpD;AAAA,EAEA,MAAM,UAAuB;AAC3B,UAA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AAW,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,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":[]}
|
@@ -1,47 +0,0 @@
|
|
1
|
-
// src/utils/define-rule.ts
|
2
|
-
var defineRule = (rule) => rule;
|
3
|
-
|
4
|
-
// src/rules/no-script-component-in-head.ts
|
5
|
-
var url = "https://nextjs.org/docs/messages/no-script-component-in-head";
|
6
|
-
var noScriptComponentInHead = defineRule({
|
7
|
-
create: (context) => {
|
8
|
-
let isNextHead = null;
|
9
|
-
return {
|
10
|
-
ImportDeclaration: (node) => {
|
11
|
-
if (node.source.value === "next/head") {
|
12
|
-
isNextHead = node.source.value;
|
13
|
-
}
|
14
|
-
},
|
15
|
-
JSXElement: (node) => {
|
16
|
-
if (!isNextHead) {
|
17
|
-
return;
|
18
|
-
}
|
19
|
-
if (node.openingElement?.name && node.openingElement.name.name !== "Head") {
|
20
|
-
return;
|
21
|
-
}
|
22
|
-
const scriptTag = node.children.find(
|
23
|
-
(child) => child.openingElement?.name && child.openingElement.name.name === "Script"
|
24
|
-
);
|
25
|
-
if (scriptTag) {
|
26
|
-
context.report({
|
27
|
-
message: `\`next/script\` should not be used in \`next/head\` component. Move \`<Script />\` outside of \`<Head>\` instead. See: ${url}`,
|
28
|
-
node
|
29
|
-
});
|
30
|
-
}
|
31
|
-
}
|
32
|
-
};
|
33
|
-
},
|
34
|
-
meta: {
|
35
|
-
docs: {
|
36
|
-
description: "Prevent usage of `next/script` in `next/head` component.",
|
37
|
-
recommended: true,
|
38
|
-
url
|
39
|
-
},
|
40
|
-
schema: [],
|
41
|
-
type: "problem"
|
42
|
-
}
|
43
|
-
});
|
44
|
-
export {
|
45
|
-
noScriptComponentInHead
|
46
|
-
};
|
47
|
-
//# sourceMappingURL=no-script-component-in-head.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../../src/utils/define-rule.ts","../../src/rules/no-script-component-in-head.ts"],"sourcesContent":["import type { Rule } from \"eslint\";\n\nexport const defineRule = (rule: Rule.RuleModule): Rule.RuleModule => rule;\n","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"],"mappings":";AAEO,IAAM,aAAa,CAAC,SAA2C;;;ACDtE,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":[]}
|
@@ -1,78 +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-styled-jsx-in-document.ts
|
31
|
-
var no_styled_jsx_in_document_exports = {};
|
32
|
-
__export(no_styled_jsx_in_document_exports, {
|
33
|
-
noStyledJsxInDocument: () => noStyledJsxInDocument
|
34
|
-
});
|
35
|
-
module.exports = __toCommonJS(no_styled_jsx_in_document_exports);
|
36
|
-
var path = __toESM(require("path"), 1);
|
37
|
-
|
38
|
-
// src/utils/define-rule.ts
|
39
|
-
var defineRule = (rule) => rule;
|
40
|
-
|
41
|
-
// src/rules/no-styled-jsx-in-document.ts
|
42
|
-
var url = "https://nextjs.org/docs/messages/no-styled-jsx-in-document";
|
43
|
-
var noStyledJsxInDocument = defineRule({
|
44
|
-
create: (context) => ({
|
45
|
-
JSXOpeningElement: (node) => {
|
46
|
-
const document = context.filename.split("pages", 2)[1];
|
47
|
-
if (!document) {
|
48
|
-
return;
|
49
|
-
}
|
50
|
-
const { dir, name } = path.parse(document);
|
51
|
-
if (!(name.startsWith("_document") || dir === "/_document" && name === "index")) {
|
52
|
-
return;
|
53
|
-
}
|
54
|
-
if (node.name.name === "style" && node.attributes.find(
|
55
|
-
(attr) => attr.type === "JSXAttribute" && attr.name.name === "jsx"
|
56
|
-
)) {
|
57
|
-
context.report({
|
58
|
-
message: `\`styled-jsx\` should not be used in \`pages/_document.js\`. See: ${url}`,
|
59
|
-
node
|
60
|
-
});
|
61
|
-
}
|
62
|
-
}
|
63
|
-
}),
|
64
|
-
meta: {
|
65
|
-
docs: {
|
66
|
-
description: "Prevent usage of `styled-jsx` in `pages/_document.js`.",
|
67
|
-
recommended: true,
|
68
|
-
url
|
69
|
-
},
|
70
|
-
schema: [],
|
71
|
-
type: "problem"
|
72
|
-
}
|
73
|
-
});
|
74
|
-
// Annotate the CommonJS export names for ESM import in node:
|
75
|
-
0 && (module.exports = {
|
76
|
-
noStyledJsxInDocument
|
77
|
-
});
|
78
|
-
//# sourceMappingURL=no-styled-jsx-in-document.cjs.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../../src/rules/no-styled-jsx-in-document.ts","../../src/utils/define-rule.ts"],"sourcesContent":["import * as path from \"node:path\";\n\nimport { defineRule } from \"../utils/define-rule.js\";\n\nconst url = \"https://nextjs.org/docs/messages/no-styled-jsx-in-document\";\n\nexport const noStyledJsxInDocument = defineRule({\n create: (context: any) => ({\n JSXOpeningElement: (node: any) => {\n const document = context.filename.split(\"pages\", 2)[1];\n if (!document) {\n return;\n }\n const { dir, name } = path.parse(document);\n\n if (\n !(\n name.startsWith(\"_document\") ||\n (dir === \"/_document\" && name === \"index\")\n )\n ) {\n return;\n }\n\n if (\n node.name.name === \"style\" &&\n node.attributes.find(\n (attr: any) =>\n attr.type === \"JSXAttribute\" && attr.name.name === \"jsx\",\n )\n ) {\n context.report({\n message: `\\`styled-jsx\\` should not be used in \\`pages/_document.js\\`. See: ${url}`,\n node,\n });\n }\n },\n }),\n meta: {\n docs: {\n description: \"Prevent usage of `styled-jsx` in `pages/_document.js`.\",\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,WAAsB;;;ACEf,IAAM,aAAa,CAAC,SAA2C;;;ADEtE,IAAM,MAAM;AAEL,IAAM,wBAAwB,WAAW;AAAA,EAC9C,QAAQ,CAAC,aAAkB;AAAA,IACzB,mBAAmB,CAAC,SAAc;AAChC,YAAM,WAAW,QAAQ,SAAS,MAAM,SAAS,CAAC,EAAE,CAAC;AACrD,UAAI,CAAC,UAAU;AACb;AAAA,MACF;AACA,YAAM,EAAE,KAAK,KAAK,IAAS,WAAM,QAAQ;AAEzC,UACE,EACE,KAAK,WAAW,WAAW,KAC1B,QAAQ,gBAAgB,SAAS,UAEpC;AACA;AAAA,MACF;AAEA,UACE,KAAK,KAAK,SAAS,WACnB,KAAK,WAAW;AAAA,QACd,CAAC,SACC,KAAK,SAAS,kBAAkB,KAAK,KAAK,SAAS;AAAA,MACvD,GACA;AACA,gBAAQ,OAAO;AAAA,UACb,SAAS,qEAAqE,GAAG;AAAA,UACjF;AAAA,QACF,CAAC;AAAA,MACH;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,43 +0,0 @@
|
|
1
|
-
// src/rules/no-styled-jsx-in-document.ts
|
2
|
-
import * as path from "node:path";
|
3
|
-
|
4
|
-
// src/utils/define-rule.ts
|
5
|
-
var defineRule = (rule) => rule;
|
6
|
-
|
7
|
-
// src/rules/no-styled-jsx-in-document.ts
|
8
|
-
var url = "https://nextjs.org/docs/messages/no-styled-jsx-in-document";
|
9
|
-
var noStyledJsxInDocument = defineRule({
|
10
|
-
create: (context) => ({
|
11
|
-
JSXOpeningElement: (node) => {
|
12
|
-
const document = context.filename.split("pages", 2)[1];
|
13
|
-
if (!document) {
|
14
|
-
return;
|
15
|
-
}
|
16
|
-
const { dir, name } = path.parse(document);
|
17
|
-
if (!(name.startsWith("_document") || dir === "/_document" && name === "index")) {
|
18
|
-
return;
|
19
|
-
}
|
20
|
-
if (node.name.name === "style" && node.attributes.find(
|
21
|
-
(attr) => attr.type === "JSXAttribute" && attr.name.name === "jsx"
|
22
|
-
)) {
|
23
|
-
context.report({
|
24
|
-
message: `\`styled-jsx\` should not be used in \`pages/_document.js\`. See: ${url}`,
|
25
|
-
node
|
26
|
-
});
|
27
|
-
}
|
28
|
-
}
|
29
|
-
}),
|
30
|
-
meta: {
|
31
|
-
docs: {
|
32
|
-
description: "Prevent usage of `styled-jsx` in `pages/_document.js`.",
|
33
|
-
recommended: true,
|
34
|
-
url
|
35
|
-
},
|
36
|
-
schema: [],
|
37
|
-
type: "problem"
|
38
|
-
}
|
39
|
-
});
|
40
|
-
export {
|
41
|
-
noStyledJsxInDocument
|
42
|
-
};
|
43
|
-
//# sourceMappingURL=no-styled-jsx-in-document.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../../src/rules/no-styled-jsx-in-document.ts","../../src/utils/define-rule.ts"],"sourcesContent":["import * as path from \"node:path\";\n\nimport { defineRule } from \"../utils/define-rule.js\";\n\nconst url = \"https://nextjs.org/docs/messages/no-styled-jsx-in-document\";\n\nexport const noStyledJsxInDocument = defineRule({\n create: (context: any) => ({\n JSXOpeningElement: (node: any) => {\n const document = context.filename.split(\"pages\", 2)[1];\n if (!document) {\n return;\n }\n const { dir, name } = path.parse(document);\n\n if (\n !(\n name.startsWith(\"_document\") ||\n (dir === \"/_document\" && name === \"index\")\n )\n ) {\n return;\n }\n\n if (\n node.name.name === \"style\" &&\n node.attributes.find(\n (attr: any) =>\n attr.type === \"JSXAttribute\" && attr.name.name === \"jsx\",\n )\n ) {\n context.report({\n message: `\\`styled-jsx\\` should not be used in \\`pages/_document.js\\`. See: ${url}`,\n node,\n });\n }\n },\n }),\n meta: {\n docs: {\n description: \"Prevent usage of `styled-jsx` in `pages/_document.js`.\",\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,YAAY,UAAU;;;ACEf,IAAM,aAAa,CAAC,SAA2C;;;ADEtE,IAAM,MAAM;AAEL,IAAM,wBAAwB,WAAW;AAAA,EAC9C,QAAQ,CAAC,aAAkB;AAAA,IACzB,mBAAmB,CAAC,SAAc;AAChC,YAAM,WAAW,QAAQ,SAAS,MAAM,SAAS,CAAC,EAAE,CAAC;AACrD,UAAI,CAAC,UAAU;AACb;AAAA,MACF;AACA,YAAM,EAAE,KAAK,KAAK,IAAS,WAAM,QAAQ;AAEzC,UACE,EACE,KAAK,WAAW,WAAW,KAC1B,QAAQ,gBAAgB,SAAS,UAEpC;AACA;AAAA,MACF;AAEA,UACE,KAAK,KAAK,SAAS,WACnB,KAAK,WAAW;AAAA,QACd,CAAC,SACC,KAAK,SAAS,kBAAkB,KAAK,KAAK,SAAS;AAAA,MACvD,GACA;AACA,gBAAQ,OAAO;AAAA,UACb,SAAS,qEAAqE,GAAG;AAAA,UACjF;AAAA,QACF,CAAC;AAAA,MACH;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,64 +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-sync-scripts.ts
|
21
|
-
var no_sync_scripts_exports = {};
|
22
|
-
__export(no_sync_scripts_exports, {
|
23
|
-
noSyncScripts: () => noSyncScripts
|
24
|
-
});
|
25
|
-
module.exports = __toCommonJS(no_sync_scripts_exports);
|
26
|
-
|
27
|
-
// src/utils/define-rule.ts
|
28
|
-
var defineRule = (rule) => rule;
|
29
|
-
|
30
|
-
// src/rules/no-sync-scripts.ts
|
31
|
-
var url = "https://nextjs.org/docs/messages/no-sync-scripts";
|
32
|
-
var noSyncScripts = defineRule({
|
33
|
-
create: (context) => ({
|
34
|
-
JSXOpeningElement: (node) => {
|
35
|
-
if (node.name.name !== "script") {
|
36
|
-
return;
|
37
|
-
}
|
38
|
-
if (node.attributes.length === 0) {
|
39
|
-
return;
|
40
|
-
}
|
41
|
-
const attributeNames = node.attributes.filter((attr) => attr.type === "JSXAttribute").map((attr) => attr.name.name);
|
42
|
-
if (attributeNames.includes("src") && !attributeNames.includes("async") && !attributeNames.includes("defer")) {
|
43
|
-
context.report({
|
44
|
-
message: `Synchronous scripts should not be used. See: ${url}`,
|
45
|
-
node
|
46
|
-
});
|
47
|
-
}
|
48
|
-
}
|
49
|
-
}),
|
50
|
-
meta: {
|
51
|
-
docs: {
|
52
|
-
description: "Prevent synchronous scripts.",
|
53
|
-
recommended: true,
|
54
|
-
url
|
55
|
-
},
|
56
|
-
schema: [],
|
57
|
-
type: "problem"
|
58
|
-
}
|
59
|
-
});
|
60
|
-
// Annotate the CommonJS export names for ESM import in node:
|
61
|
-
0 && (module.exports = {
|
62
|
-
noSyncScripts
|
63
|
-
});
|
64
|
-
//# sourceMappingURL=no-sync-scripts.cjs.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../../src/rules/no-sync-scripts.ts","../../src/utils/define-rule.ts"],"sourcesContent":["import { defineRule } from \"../utils/define-rule.js\";\n\nconst url = \"https://nextjs.org/docs/messages/no-sync-scripts\";\n\nexport const noSyncScripts = defineRule({\n create: (context: any) => ({\n JSXOpeningElement: (node: any) => {\n if (node.name.name !== \"script\") {\n return;\n }\n if (node.attributes.length === 0) {\n return;\n }\n const attributeNames = node.attributes\n .filter((attr: any) => attr.type === \"JSXAttribute\")\n .map((attr: any) => attr.name.name);\n if (\n attributeNames.includes(\"src\") &&\n !attributeNames.includes(\"async\") &&\n !attributeNames.includes(\"defer\")\n ) {\n context.report({\n message: `Synchronous scripts should not be used. See: ${url}`,\n node,\n });\n }\n },\n }),\n meta: {\n docs: {\n description: \"Prevent synchronous scripts.\",\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;;;ADAtE,IAAM,MAAM;AAEL,IAAM,gBAAgB,WAAW;AAAA,EACtC,QAAQ,CAAC,aAAkB;AAAA,IACzB,mBAAmB,CAAC,SAAc;AAChC,UAAI,KAAK,KAAK,SAAS,UAAU;AAC/B;AAAA,MACF;AACA,UAAI,KAAK,WAAW,WAAW,GAAG;AAChC;AAAA,MACF;AACA,YAAM,iBAAiB,KAAK,WACzB,OAAO,CAAC,SAAc,KAAK,SAAS,cAAc,EAClD,IAAI,CAAC,SAAc,KAAK,KAAK,IAAI;AACpC,UACE,eAAe,SAAS,KAAK,KAC7B,CAAC,eAAe,SAAS,OAAO,KAChC,CAAC,eAAe,SAAS,OAAO,GAChC;AACA,gBAAQ,OAAO;AAAA,UACb,SAAS,gDAAgD,GAAG;AAAA,UAC5D;AAAA,QACF,CAAC;AAAA,MACH;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":[]}
|