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,137 +0,0 @@
|
|
1
|
-
// src/utils/define-rule.ts
|
2
|
-
var defineRule = (rule) => rule;
|
3
|
-
|
4
|
-
// src/rules/no-unwanted-polyfillio.ts
|
5
|
-
var NEXT_POLYFILLED_FEATURES = [
|
6
|
-
"Array.prototype.@@iterator",
|
7
|
-
"Array.prototype.at",
|
8
|
-
"Array.prototype.copyWithin",
|
9
|
-
"Array.prototype.fill",
|
10
|
-
"Array.prototype.find",
|
11
|
-
"Array.prototype.findIndex",
|
12
|
-
"Array.prototype.flatMap",
|
13
|
-
"Array.prototype.flat",
|
14
|
-
"Array.from",
|
15
|
-
"Array.prototype.includes",
|
16
|
-
"Array.of",
|
17
|
-
"Function.prototype.name",
|
18
|
-
"fetch",
|
19
|
-
"Map",
|
20
|
-
"Number.EPSILON",
|
21
|
-
"Number.Epsilon",
|
22
|
-
"Number.isFinite",
|
23
|
-
"Number.isNaN",
|
24
|
-
"Number.isInteger",
|
25
|
-
"Number.isSafeInteger",
|
26
|
-
"Number.MAX_SAFE_INTEGER",
|
27
|
-
"Number.MIN_SAFE_INTEGER",
|
28
|
-
"Number.parseFloat",
|
29
|
-
"Number.parseInt",
|
30
|
-
"Object.assign",
|
31
|
-
"Object.entries",
|
32
|
-
"Object.fromEntries",
|
33
|
-
"Object.getOwnPropertyDescriptor",
|
34
|
-
"Object.getOwnPropertyDescriptors",
|
35
|
-
"Object.hasOwn",
|
36
|
-
"Object.is",
|
37
|
-
"Object.keys",
|
38
|
-
"Object.values",
|
39
|
-
"Reflect",
|
40
|
-
"Set",
|
41
|
-
"Symbol",
|
42
|
-
"Symbol.asyncIterator",
|
43
|
-
"String.prototype.codePointAt",
|
44
|
-
"String.prototype.endsWith",
|
45
|
-
"String.fromCodePoint",
|
46
|
-
"String.prototype.includes",
|
47
|
-
"String.prototype.@@iterator",
|
48
|
-
"String.prototype.padEnd",
|
49
|
-
"String.prototype.padStart",
|
50
|
-
"String.prototype.repeat",
|
51
|
-
"String.raw",
|
52
|
-
"String.prototype.startsWith",
|
53
|
-
"String.prototype.trimEnd",
|
54
|
-
"String.prototype.trimStart",
|
55
|
-
"URL",
|
56
|
-
"URL.prototype.toJSON",
|
57
|
-
"URLSearchParams",
|
58
|
-
"WeakMap",
|
59
|
-
"WeakSet",
|
60
|
-
"Promise",
|
61
|
-
"Promise.prototype.finally",
|
62
|
-
"es2015",
|
63
|
-
// Should be covered by babel-preset-env instead.
|
64
|
-
"es2016",
|
65
|
-
// contains polyfilled 'Array.prototype.includes', 'String.prototype.padEnd' and 'String.prototype.padStart'
|
66
|
-
"es2017",
|
67
|
-
// contains polyfilled 'Object.entries', 'Object.getOwnPropertyDescriptors', 'Object.values', 'String.prototype.padEnd' and 'String.prototype.padStart'
|
68
|
-
"es2018",
|
69
|
-
// contains polyfilled 'Promise.prototype.finally' and ''Symbol.asyncIterator'
|
70
|
-
"es2019",
|
71
|
-
// Contains polyfilled 'Object.fromEntries' and polyfilled 'Array.prototype.flat', 'Array.prototype.flatMap', 'String.prototype.trimEnd' and 'String.prototype.trimStart'
|
72
|
-
"es5",
|
73
|
-
// Should be covered by babel-preset-env instead.
|
74
|
-
"es6",
|
75
|
-
// Should be covered by babel-preset-env instead.
|
76
|
-
"es7"
|
77
|
-
// contains polyfilled 'Array.prototype.includes', 'String.prototype.padEnd' and 'String.prototype.padStart'
|
78
|
-
];
|
79
|
-
var url = "https://nextjs.org/docs/messages/no-unwanted-polyfillio";
|
80
|
-
var noUnwantedPolyfillio = defineRule({
|
81
|
-
create: (context) => {
|
82
|
-
let scriptImport = null;
|
83
|
-
return {
|
84
|
-
ImportDeclaration: (node) => {
|
85
|
-
if (node.source && node.source.value === "next/script") {
|
86
|
-
scriptImport = node.specifiers[0].local.name;
|
87
|
-
}
|
88
|
-
},
|
89
|
-
JSXOpeningElement: (node) => {
|
90
|
-
if (node.name && node.name.name !== "script" && node.name.name !== scriptImport) {
|
91
|
-
return;
|
92
|
-
}
|
93
|
-
if (node.attributes.length === 0) {
|
94
|
-
return;
|
95
|
-
}
|
96
|
-
const srcNode = node.attributes.find(
|
97
|
-
(attr) => attr.type === "JSXAttribute" && attr.name.name === "src"
|
98
|
-
);
|
99
|
-
if (!srcNode || srcNode.value.type !== "Literal") {
|
100
|
-
return;
|
101
|
-
}
|
102
|
-
const src = srcNode.value.value;
|
103
|
-
if (src.startsWith("https://cdn.polyfill.io/v2/") || src.startsWith("https://polyfill.io/v3/") || // https://community.fastly.com/t/new-options-for-polyfill-io-users/2540
|
104
|
-
src.startsWith("https://polyfill-fastly.net/") || src.startsWith("https://polyfill-fastly.io/") || // https://blog.cloudflare.com/polyfill-io-now-available-on-cdnjs-reduce-your-supply-chain-risk
|
105
|
-
src.startsWith("https://cdnjs.cloudflare.com/polyfill/")) {
|
106
|
-
const featureQueryString = new URL(src).searchParams.get("features");
|
107
|
-
const featuresRequested = (featureQueryString ?? "").split(",");
|
108
|
-
const unwantedFeatures = featuresRequested.filter(
|
109
|
-
(feature) => NEXT_POLYFILLED_FEATURES.includes(feature)
|
110
|
-
);
|
111
|
-
if (unwantedFeatures.length > 0) {
|
112
|
-
context.report({
|
113
|
-
message: `No duplicate polyfills from Polyfill.io are allowed. ${unwantedFeatures.join(
|
114
|
-
", "
|
115
|
-
)} ${unwantedFeatures.length > 1 ? "are" : "is"} already shipped with Next.js. See: ${url}`,
|
116
|
-
node
|
117
|
-
});
|
118
|
-
}
|
119
|
-
}
|
120
|
-
}
|
121
|
-
};
|
122
|
-
},
|
123
|
-
meta: {
|
124
|
-
docs: {
|
125
|
-
category: "HTML",
|
126
|
-
description: "Prevent duplicate polyfills from Polyfill.io.",
|
127
|
-
recommended: true,
|
128
|
-
url
|
129
|
-
},
|
130
|
-
schema: [],
|
131
|
-
type: "problem"
|
132
|
-
}
|
133
|
-
});
|
134
|
-
export {
|
135
|
-
noUnwantedPolyfillio
|
136
|
-
};
|
137
|
-
//# sourceMappingURL=no-unwanted-polyfillio.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../../src/utils/define-rule.ts","../../src/rules/no-unwanted-polyfillio.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\";\n\n// Keep in sync with next.js polyfills file : https://github.com/vercel/next.js/blob/master/packages/next-polyfill-nomodule/src/index.js\nconst NEXT_POLYFILLED_FEATURES = [\n \"Array.prototype.@@iterator\",\n \"Array.prototype.at\",\n \"Array.prototype.copyWithin\",\n \"Array.prototype.fill\",\n \"Array.prototype.find\",\n \"Array.prototype.findIndex\",\n \"Array.prototype.flatMap\",\n \"Array.prototype.flat\",\n \"Array.from\",\n \"Array.prototype.includes\",\n \"Array.of\",\n \"Function.prototype.name\",\n \"fetch\",\n \"Map\",\n \"Number.EPSILON\",\n \"Number.Epsilon\",\n \"Number.isFinite\",\n \"Number.isNaN\",\n \"Number.isInteger\",\n \"Number.isSafeInteger\",\n \"Number.MAX_SAFE_INTEGER\",\n \"Number.MIN_SAFE_INTEGER\",\n \"Number.parseFloat\",\n \"Number.parseInt\",\n \"Object.assign\",\n \"Object.entries\",\n \"Object.fromEntries\",\n \"Object.getOwnPropertyDescriptor\",\n \"Object.getOwnPropertyDescriptors\",\n \"Object.hasOwn\",\n \"Object.is\",\n \"Object.keys\",\n \"Object.values\",\n \"Reflect\",\n \"Set\",\n \"Symbol\",\n \"Symbol.asyncIterator\",\n \"String.prototype.codePointAt\",\n \"String.prototype.endsWith\",\n \"String.fromCodePoint\",\n \"String.prototype.includes\",\n \"String.prototype.@@iterator\",\n \"String.prototype.padEnd\",\n \"String.prototype.padStart\",\n \"String.prototype.repeat\",\n \"String.raw\",\n \"String.prototype.startsWith\",\n \"String.prototype.trimEnd\",\n \"String.prototype.trimStart\",\n \"URL\",\n \"URL.prototype.toJSON\",\n \"URLSearchParams\",\n \"WeakMap\",\n \"WeakSet\",\n \"Promise\",\n \"Promise.prototype.finally\",\n \"es2015\", // Should be covered by babel-preset-env instead.\n \"es2016\", // contains polyfilled 'Array.prototype.includes', 'String.prototype.padEnd' and 'String.prototype.padStart'\n \"es2017\", // contains polyfilled 'Object.entries', 'Object.getOwnPropertyDescriptors', 'Object.values', 'String.prototype.padEnd' and 'String.prototype.padStart'\n \"es2018\", // contains polyfilled 'Promise.prototype.finally' and ''Symbol.asyncIterator'\n \"es2019\", // Contains polyfilled 'Object.fromEntries' and polyfilled 'Array.prototype.flat', 'Array.prototype.flatMap', 'String.prototype.trimEnd' and 'String.prototype.trimStart'\n \"es5\", // Should be covered by babel-preset-env instead.\n \"es6\", // Should be covered by babel-preset-env instead.\n \"es7\", // contains polyfilled 'Array.prototype.includes', 'String.prototype.padEnd' and 'String.prototype.padStart'\n];\n\nconst url = \"https://nextjs.org/docs/messages/no-unwanted-polyfillio\";\n\n//------------------------------------------------------------------------------\n// Rule Definition\n//------------------------------------------------------------------------------\nexport const noUnwantedPolyfillio = defineRule({\n create: (context: any) => {\n let scriptImport: null | string = null;\n\n return {\n ImportDeclaration: (node: any) => {\n if (node.source && node.source.value === \"next/script\") {\n scriptImport = node.specifiers[0].local.name;\n }\n },\n JSXOpeningElement: (node: any) => {\n if (\n node.name &&\n node.name.name !== \"script\" &&\n node.name.name !== scriptImport\n ) {\n return;\n }\n if (node.attributes.length === 0) {\n return;\n }\n\n const srcNode = node.attributes.find(\n (attr: any) =>\n attr.type === \"JSXAttribute\" && attr.name.name === \"src\",\n );\n if (!srcNode || srcNode.value.type !== \"Literal\") {\n return;\n }\n const src = srcNode.value.value;\n if (\n src.startsWith(\"https://cdn.polyfill.io/v2/\") ||\n src.startsWith(\"https://polyfill.io/v3/\") ||\n // https://community.fastly.com/t/new-options-for-polyfill-io-users/2540\n src.startsWith(\"https://polyfill-fastly.net/\") ||\n src.startsWith(\"https://polyfill-fastly.io/\") ||\n // https://blog.cloudflare.com/polyfill-io-now-available-on-cdnjs-reduce-your-supply-chain-risk\n src.startsWith(\"https://cdnjs.cloudflare.com/polyfill/\")\n ) {\n const featureQueryString = new URL(src).searchParams.get(\"features\");\n const featuresRequested = (featureQueryString ?? \"\").split(\",\");\n const unwantedFeatures = featuresRequested.filter((feature) =>\n NEXT_POLYFILLED_FEATURES.includes(feature),\n );\n if (unwantedFeatures.length > 0) {\n context.report({\n message: `No duplicate polyfills from Polyfill.io are allowed. ${unwantedFeatures.join(\n \", \",\n )} ${\n unwantedFeatures.length > 1 ? \"are\" : \"is\"\n } already shipped with Next.js. See: ${url}`,\n node,\n });\n }\n }\n },\n };\n },\n\n meta: {\n docs: {\n category: \"HTML\",\n description: \"Prevent duplicate polyfills from Polyfill.io.\",\n recommended: true,\n url,\n },\n schema: [],\n type: \"problem\",\n },\n});\n"],"mappings":";AAEO,IAAM,aAAa,CAAC,SAA2C;;;ACCtE,IAAM,2BAA2B;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AACF;AAEA,IAAM,MAAM;AAKL,IAAM,uBAAuB,WAAW;AAAA,EAC7C,QAAQ,CAAC,YAAiB;AACxB,QAAI,eAA8B;AAElC,WAAO;AAAA,MACL,mBAAmB,CAAC,SAAc;AAChC,YAAI,KAAK,UAAU,KAAK,OAAO,UAAU,eAAe;AACtD,yBAAe,KAAK,WAAW,CAAC,EAAE,MAAM;AAAA,QAC1C;AAAA,MACF;AAAA,MACA,mBAAmB,CAAC,SAAc;AAChC,YACE,KAAK,QACL,KAAK,KAAK,SAAS,YACnB,KAAK,KAAK,SAAS,cACnB;AACA;AAAA,QACF;AACA,YAAI,KAAK,WAAW,WAAW,GAAG;AAChC;AAAA,QACF;AAEA,cAAM,UAAU,KAAK,WAAW;AAAA,UAC9B,CAAC,SACC,KAAK,SAAS,kBAAkB,KAAK,KAAK,SAAS;AAAA,QACvD;AACA,YAAI,CAAC,WAAW,QAAQ,MAAM,SAAS,WAAW;AAChD;AAAA,QACF;AACA,cAAM,MAAM,QAAQ,MAAM;AAC1B,YACE,IAAI,WAAW,6BAA6B,KAC5C,IAAI,WAAW,yBAAyB;AAAA,QAExC,IAAI,WAAW,8BAA8B,KAC7C,IAAI,WAAW,6BAA6B;AAAA,QAE5C,IAAI,WAAW,wCAAwC,GACvD;AACA,gBAAM,qBAAqB,IAAI,IAAI,GAAG,EAAE,aAAa,IAAI,UAAU;AACnE,gBAAM,qBAAqB,sBAAsB,IAAI,MAAM,GAAG;AAC9D,gBAAM,mBAAmB,kBAAkB;AAAA,YAAO,CAAC,YACjD,yBAAyB,SAAS,OAAO;AAAA,UAC3C;AACA,cAAI,iBAAiB,SAAS,GAAG;AAC/B,oBAAQ,OAAO;AAAA,cACb,SAAS,wDAAwD,iBAAiB;AAAA,gBAChF;AAAA,cACF,CAAC,IACC,iBAAiB,SAAS,IAAI,QAAQ,IACxC,uCAAuC,GAAG;AAAA,cAC1C;AAAA,YACF,CAAC;AAAA,UACH;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EAEA,MAAM;AAAA,IACJ,MAAM;AAAA,MACJ,UAAU;AAAA,MACV,aAAa;AAAA,MACb,aAAa;AAAA,MACb;AAAA,IACF;AAAA,IACA,QAAQ,CAAC;AAAA,IACT,MAAM;AAAA,EACR;AACF,CAAC;","names":[]}
|
@@ -1,31 +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/utils/define-rule.ts
|
21
|
-
var define_rule_exports = {};
|
22
|
-
__export(define_rule_exports, {
|
23
|
-
defineRule: () => defineRule
|
24
|
-
});
|
25
|
-
module.exports = __toCommonJS(define_rule_exports);
|
26
|
-
var defineRule = (rule) => rule;
|
27
|
-
// Annotate the CommonJS export names for ESM import in node:
|
28
|
-
0 && (module.exports = {
|
29
|
-
defineRule
|
30
|
-
});
|
31
|
-
//# sourceMappingURL=define-rule.cjs.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../../src/utils/define-rule.ts"],"sourcesContent":["import type { Rule } from \"eslint\";\n\nexport const defineRule = (rule: Rule.RuleModule): Rule.RuleModule => rule;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,IAAM,aAAa,CAAC,SAA2C;","names":[]}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../../src/utils/define-rule.ts"],"sourcesContent":["import type { Rule } from \"eslint\";\n\nexport const defineRule = (rule: Rule.RuleModule): Rule.RuleModule => rule;\n"],"mappings":";AAEO,IAAM,aAAa,CAAC,SAA2C;","names":[]}
|
@@ -1,60 +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/utils/get-root-dirs.ts
|
31
|
-
var get_root_dirs_exports = {};
|
32
|
-
__export(get_root_dirs_exports, {
|
33
|
-
getRootDirs: () => getRootDirs
|
34
|
-
});
|
35
|
-
module.exports = __toCommonJS(get_root_dirs_exports);
|
36
|
-
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
37
|
-
var processRootDir = (rootDir) => {
|
38
|
-
return import_fast_glob.default.globSync(rootDir.replaceAll("\\", "/"), {
|
39
|
-
onlyDirectories: true
|
40
|
-
});
|
41
|
-
};
|
42
|
-
var getRootDirs = (context) => {
|
43
|
-
let rootDirs = [context.cwd];
|
44
|
-
const nextSettings = (
|
45
|
-
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
46
|
-
context.settings.next || {}
|
47
|
-
);
|
48
|
-
const rootDir = nextSettings.rootDir;
|
49
|
-
if (typeof rootDir === "string") {
|
50
|
-
rootDirs = processRootDir(rootDir);
|
51
|
-
} else if (Array.isArray(rootDir)) {
|
52
|
-
rootDirs = rootDir.map((dir) => typeof dir === "string" ? processRootDir(dir) : []).flat();
|
53
|
-
}
|
54
|
-
return rootDirs;
|
55
|
-
};
|
56
|
-
// Annotate the CommonJS export names for ESM import in node:
|
57
|
-
0 && (module.exports = {
|
58
|
-
getRootDirs
|
59
|
-
});
|
60
|
-
//# sourceMappingURL=get-root-dirs.cjs.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../../src/utils/get-root-dirs.ts"],"sourcesContent":["import type { Rule } from \"eslint\";\n\nimport fastGlob from \"fast-glob\";\n\n/**\n * Process a Next.js root directory glob.\n */\nconst processRootDir = (rootDir: string): string[] => {\n return fastGlob.globSync(rootDir.replaceAll(\"\\\\\", \"/\"), {\n onlyDirectories: true,\n });\n};\n\n/**\n * Gets one or more Root, returns an array of root directories.\n */\nexport const getRootDirs = (context: Rule.RuleContext) => {\n let rootDirs = [context.cwd];\n\n const nextSettings: { rootDir?: string | string[] } =\n // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n context.settings.next || {};\n const rootDir = nextSettings.rootDir;\n\n if (typeof rootDir === \"string\") {\n rootDirs = processRootDir(rootDir);\n } else if (Array.isArray(rootDir)) {\n rootDirs = rootDir\n .map((dir) => (typeof dir === \"string\" ? processRootDir(dir) : []))\n .flat();\n }\n\n return rootDirs;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,uBAAqB;AAKrB,IAAM,iBAAiB,CAAC,YAA8B;AACpD,SAAO,iBAAAA,QAAS,SAAS,QAAQ,WAAW,MAAM,GAAG,GAAG;AAAA,IACtD,iBAAiB;AAAA,EACnB,CAAC;AACH;AAKO,IAAM,cAAc,CAAC,YAA8B;AACxD,MAAI,WAAW,CAAC,QAAQ,GAAG;AAE3B,QAAM;AAAA;AAAA,IAEJ,QAAQ,SAAS,QAAQ,CAAC;AAAA;AAC5B,QAAM,UAAU,aAAa;AAE7B,MAAI,OAAO,YAAY,UAAU;AAC/B,eAAW,eAAe,OAAO;AAAA,EACnC,WAAW,MAAM,QAAQ,OAAO,GAAG;AACjC,eAAW,QACR,IAAI,CAAC,QAAS,OAAO,QAAQ,WAAW,eAAe,GAAG,IAAI,CAAC,CAAE,EACjE,KAAK;AAAA,EACV;AAEA,SAAO;AACT;","names":["fastGlob"]}
|
@@ -1,25 +0,0 @@
|
|
1
|
-
// src/utils/get-root-dirs.ts
|
2
|
-
import fastGlob from "fast-glob";
|
3
|
-
var processRootDir = (rootDir) => {
|
4
|
-
return fastGlob.globSync(rootDir.replaceAll("\\", "/"), {
|
5
|
-
onlyDirectories: true
|
6
|
-
});
|
7
|
-
};
|
8
|
-
var getRootDirs = (context) => {
|
9
|
-
let rootDirs = [context.cwd];
|
10
|
-
const nextSettings = (
|
11
|
-
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
12
|
-
context.settings.next || {}
|
13
|
-
);
|
14
|
-
const rootDir = nextSettings.rootDir;
|
15
|
-
if (typeof rootDir === "string") {
|
16
|
-
rootDirs = processRootDir(rootDir);
|
17
|
-
} else if (Array.isArray(rootDir)) {
|
18
|
-
rootDirs = rootDir.map((dir) => typeof dir === "string" ? processRootDir(dir) : []).flat();
|
19
|
-
}
|
20
|
-
return rootDirs;
|
21
|
-
};
|
22
|
-
export {
|
23
|
-
getRootDirs
|
24
|
-
};
|
25
|
-
//# sourceMappingURL=get-root-dirs.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../../src/utils/get-root-dirs.ts"],"sourcesContent":["import type { Rule } from \"eslint\";\n\nimport fastGlob from \"fast-glob\";\n\n/**\n * Process a Next.js root directory glob.\n */\nconst processRootDir = (rootDir: string): string[] => {\n return fastGlob.globSync(rootDir.replaceAll(\"\\\\\", \"/\"), {\n onlyDirectories: true,\n });\n};\n\n/**\n * Gets one or more Root, returns an array of root directories.\n */\nexport const getRootDirs = (context: Rule.RuleContext) => {\n let rootDirs = [context.cwd];\n\n const nextSettings: { rootDir?: string | string[] } =\n // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n context.settings.next || {};\n const rootDir = nextSettings.rootDir;\n\n if (typeof rootDir === \"string\") {\n rootDirs = processRootDir(rootDir);\n } else if (Array.isArray(rootDir)) {\n rootDirs = rootDir\n .map((dir) => (typeof dir === \"string\" ? processRootDir(dir) : []))\n .flat();\n }\n\n return rootDirs;\n};\n"],"mappings":";AAEA,OAAO,cAAc;AAKrB,IAAM,iBAAiB,CAAC,YAA8B;AACpD,SAAO,SAAS,SAAS,QAAQ,WAAW,MAAM,GAAG,GAAG;AAAA,IACtD,iBAAiB;AAAA,EACnB,CAAC;AACH;AAKO,IAAM,cAAc,CAAC,YAA8B;AACxD,MAAI,WAAW,CAAC,QAAQ,GAAG;AAE3B,QAAM;AAAA;AAAA,IAEJ,QAAQ,SAAS,QAAQ,CAAC;AAAA;AAC5B,QAAM,UAAU,aAAa;AAE7B,MAAI,OAAO,YAAY,UAAU;AAC/B,eAAW,eAAe,OAAO;AAAA,EACnC,WAAW,MAAM,QAAQ,OAAO,GAAG;AACjC,eAAW,QACR,IAAI,CAAC,QAAS,OAAO,QAAQ,WAAW,eAAe,GAAG,IAAI,CAAC,CAAE,EACjE,KAAK;AAAA,EACV;AAEA,SAAO;AACT;","names":[]}
|
@@ -1,67 +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/utils/node-attributes.ts
|
21
|
-
var node_attributes_exports = {};
|
22
|
-
__export(node_attributes_exports, {
|
23
|
-
default: () => NodeAttributes
|
24
|
-
});
|
25
|
-
module.exports = __toCommonJS(node_attributes_exports);
|
26
|
-
var NodeAttributes = class {
|
27
|
-
attributes;
|
28
|
-
constructor(ASTnode) {
|
29
|
-
this.attributes = {};
|
30
|
-
ASTnode.attributes.forEach((attribute) => {
|
31
|
-
if (!attribute.type || attribute.type !== "JSXAttribute") {
|
32
|
-
return;
|
33
|
-
}
|
34
|
-
if (attribute.value) {
|
35
|
-
const value = typeof attribute.value.value === "string" ? attribute.value.value : typeof attribute.value.expression?.value !== "undefined" ? attribute.value.expression.value : attribute.value.expression?.properties;
|
36
|
-
this.attributes[attribute.name.name] = {
|
37
|
-
hasValue: true,
|
38
|
-
value
|
39
|
-
};
|
40
|
-
} else {
|
41
|
-
this.attributes[attribute.name.name] = {
|
42
|
-
hasValue: false
|
43
|
-
};
|
44
|
-
}
|
45
|
-
});
|
46
|
-
}
|
47
|
-
has(attrName) {
|
48
|
-
return Boolean(this.attributes[attrName]);
|
49
|
-
}
|
50
|
-
hasAny() {
|
51
|
-
return Boolean(Object.keys(this.attributes).length);
|
52
|
-
}
|
53
|
-
hasValue(attrName) {
|
54
|
-
return Boolean(this.attributes[attrName]?.hasValue);
|
55
|
-
}
|
56
|
-
value(attrName) {
|
57
|
-
const attr = this.attributes[attrName];
|
58
|
-
if (!attr) {
|
59
|
-
return true;
|
60
|
-
}
|
61
|
-
if ("hasValue" in attr && attr.hasValue) {
|
62
|
-
return attr.value;
|
63
|
-
}
|
64
|
-
return void 0;
|
65
|
-
}
|
66
|
-
};
|
67
|
-
//# sourceMappingURL=node-attributes.cjs.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../../src/utils/node-attributes.ts"],"sourcesContent":["// 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;AAaA,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,UAAM,OAAO,KAAK,WAAW,QAAQ;AAErC,QAAI,CAAC,MAAM;AACT,aAAO;AAAA,IACT;AAEA,QAAI,cAAc,QAAQ,KAAK,UAAU;AACvC,aAAO,KAAK;AAAA,IACd;AAEA,WAAO;AAAA,EACT;AACF;","names":[]}
|
@@ -1,15 +0,0 @@
|
|
1
|
-
declare class NodeAttributes {
|
2
|
-
attributes: Record<string, {
|
3
|
-
hasValue: true;
|
4
|
-
value: any;
|
5
|
-
} | {
|
6
|
-
hasValue?: false;
|
7
|
-
}>;
|
8
|
-
constructor(ASTnode: any);
|
9
|
-
has(attrName: string): boolean;
|
10
|
-
hasAny(): boolean;
|
11
|
-
hasValue(attrName: string): boolean;
|
12
|
-
value(attrName: string): any;
|
13
|
-
}
|
14
|
-
|
15
|
-
export { NodeAttributes as default };
|
@@ -1,15 +0,0 @@
|
|
1
|
-
declare class NodeAttributes {
|
2
|
-
attributes: Record<string, {
|
3
|
-
hasValue: true;
|
4
|
-
value: any;
|
5
|
-
} | {
|
6
|
-
hasValue?: false;
|
7
|
-
}>;
|
8
|
-
constructor(ASTnode: any);
|
9
|
-
has(attrName: string): boolean;
|
10
|
-
hasAny(): boolean;
|
11
|
-
hasValue(attrName: string): boolean;
|
12
|
-
value(attrName: string): any;
|
13
|
-
}
|
14
|
-
|
15
|
-
export { NodeAttributes as default };
|
@@ -1,46 +0,0 @@
|
|
1
|
-
// src/utils/node-attributes.ts
|
2
|
-
var NodeAttributes = class {
|
3
|
-
attributes;
|
4
|
-
constructor(ASTnode) {
|
5
|
-
this.attributes = {};
|
6
|
-
ASTnode.attributes.forEach((attribute) => {
|
7
|
-
if (!attribute.type || attribute.type !== "JSXAttribute") {
|
8
|
-
return;
|
9
|
-
}
|
10
|
-
if (attribute.value) {
|
11
|
-
const value = typeof attribute.value.value === "string" ? attribute.value.value : typeof attribute.value.expression?.value !== "undefined" ? attribute.value.expression.value : attribute.value.expression?.properties;
|
12
|
-
this.attributes[attribute.name.name] = {
|
13
|
-
hasValue: true,
|
14
|
-
value
|
15
|
-
};
|
16
|
-
} else {
|
17
|
-
this.attributes[attribute.name.name] = {
|
18
|
-
hasValue: false
|
19
|
-
};
|
20
|
-
}
|
21
|
-
});
|
22
|
-
}
|
23
|
-
has(attrName) {
|
24
|
-
return Boolean(this.attributes[attrName]);
|
25
|
-
}
|
26
|
-
hasAny() {
|
27
|
-
return Boolean(Object.keys(this.attributes).length);
|
28
|
-
}
|
29
|
-
hasValue(attrName) {
|
30
|
-
return Boolean(this.attributes[attrName]?.hasValue);
|
31
|
-
}
|
32
|
-
value(attrName) {
|
33
|
-
const attr = this.attributes[attrName];
|
34
|
-
if (!attr) {
|
35
|
-
return true;
|
36
|
-
}
|
37
|
-
if ("hasValue" in attr && attr.hasValue) {
|
38
|
-
return attr.value;
|
39
|
-
}
|
40
|
-
return void 0;
|
41
|
-
}
|
42
|
-
};
|
43
|
-
export {
|
44
|
-
NodeAttributes as default
|
45
|
-
};
|
46
|
-
//# sourceMappingURL=node-attributes.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../../src/utils/node-attributes.ts"],"sourcesContent":["// 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,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,UAAM,OAAO,KAAK,WAAW,QAAQ;AAErC,QAAI,CAAC,MAAM;AACT,aAAO;AAAA,IACT;AAEA,QAAI,cAAc,QAAQ,KAAK,UAAU;AACvC,aAAO,KAAK;AAAA,IACd;AAEA,WAAO;AAAA,EACT;AACF;","names":[]}
|