@next/eslint-plugin-next 14.3.0-canary.9 → 15.0.0-rc.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/dist/index.js CHANGED
@@ -1,69 +1,69 @@
1
1
  "use strict";
2
2
  module.exports = {
3
3
  rules: {
4
- "google-font-display": require("./rules/google-font-display"),
5
- "google-font-preconnect": require("./rules/google-font-preconnect"),
6
- "inline-script-id": require("./rules/inline-script-id"),
7
- "next-script-for-ga": require("./rules/next-script-for-ga"),
8
- "no-assign-module-variable": require("./rules/no-assign-module-variable"),
9
- "no-async-client-component": require("./rules/no-async-client-component"),
10
- "no-before-interactive-script-outside-document": require("./rules/no-before-interactive-script-outside-document"),
11
- "no-css-tags": require("./rules/no-css-tags"),
12
- "no-document-import-in-page": require("./rules/no-document-import-in-page"),
13
- "no-duplicate-head": require("./rules/no-duplicate-head"),
14
- "no-head-element": require("./rules/no-head-element"),
15
- "no-head-import-in-document": require("./rules/no-head-import-in-document"),
16
- "no-html-link-for-pages": require("./rules/no-html-link-for-pages"),
17
- "no-img-element": require("./rules/no-img-element"),
18
- "no-page-custom-font": require("./rules/no-page-custom-font"),
19
- "no-script-component-in-head": require("./rules/no-script-component-in-head"),
20
- "no-styled-jsx-in-document": require("./rules/no-styled-jsx-in-document"),
21
- "no-sync-scripts": require("./rules/no-sync-scripts"),
22
- "no-title-in-document-head": require("./rules/no-title-in-document-head"),
23
- "no-typos": require("./rules/no-typos"),
24
- "no-unwanted-polyfillio": require("./rules/no-unwanted-polyfillio")
4
+ 'google-font-display': require('./rules/google-font-display'),
5
+ 'google-font-preconnect': require('./rules/google-font-preconnect'),
6
+ 'inline-script-id': require('./rules/inline-script-id'),
7
+ 'next-script-for-ga': require('./rules/next-script-for-ga'),
8
+ 'no-assign-module-variable': require('./rules/no-assign-module-variable'),
9
+ 'no-async-client-component': require('./rules/no-async-client-component'),
10
+ 'no-before-interactive-script-outside-document': require('./rules/no-before-interactive-script-outside-document'),
11
+ 'no-css-tags': require('./rules/no-css-tags'),
12
+ 'no-document-import-in-page': require('./rules/no-document-import-in-page'),
13
+ 'no-duplicate-head': require('./rules/no-duplicate-head'),
14
+ 'no-head-element': require('./rules/no-head-element'),
15
+ 'no-head-import-in-document': require('./rules/no-head-import-in-document'),
16
+ 'no-html-link-for-pages': require('./rules/no-html-link-for-pages'),
17
+ 'no-img-element': require('./rules/no-img-element'),
18
+ 'no-page-custom-font': require('./rules/no-page-custom-font'),
19
+ 'no-script-component-in-head': require('./rules/no-script-component-in-head'),
20
+ 'no-styled-jsx-in-document': require('./rules/no-styled-jsx-in-document'),
21
+ 'no-sync-scripts': require('./rules/no-sync-scripts'),
22
+ 'no-title-in-document-head': require('./rules/no-title-in-document-head'),
23
+ 'no-typos': require('./rules/no-typos'),
24
+ 'no-unwanted-polyfillio': require('./rules/no-unwanted-polyfillio')
25
25
  },
26
26
  configs: {
27
27
  recommended: {
28
28
  plugins: [
29
- "@next/next"
29
+ '@next/next'
30
30
  ],
31
31
  rules: {
32
32
  // warnings
33
- "@next/next/google-font-display": "warn",
34
- "@next/next/google-font-preconnect": "warn",
35
- "@next/next/next-script-for-ga": "warn",
36
- "@next/next/no-async-client-component": "warn",
37
- "@next/next/no-before-interactive-script-outside-document": "warn",
38
- "@next/next/no-css-tags": "warn",
39
- "@next/next/no-head-element": "warn",
40
- "@next/next/no-html-link-for-pages": "warn",
41
- "@next/next/no-img-element": "warn",
42
- "@next/next/no-page-custom-font": "warn",
43
- "@next/next/no-styled-jsx-in-document": "warn",
44
- "@next/next/no-sync-scripts": "warn",
45
- "@next/next/no-title-in-document-head": "warn",
46
- "@next/next/no-typos": "warn",
47
- "@next/next/no-unwanted-polyfillio": "warn",
33
+ '@next/next/google-font-display': 'warn',
34
+ '@next/next/google-font-preconnect': 'warn',
35
+ '@next/next/next-script-for-ga': 'warn',
36
+ '@next/next/no-async-client-component': 'warn',
37
+ '@next/next/no-before-interactive-script-outside-document': 'warn',
38
+ '@next/next/no-css-tags': 'warn',
39
+ '@next/next/no-head-element': 'warn',
40
+ '@next/next/no-html-link-for-pages': 'warn',
41
+ '@next/next/no-img-element': 'warn',
42
+ '@next/next/no-page-custom-font': 'warn',
43
+ '@next/next/no-styled-jsx-in-document': 'warn',
44
+ '@next/next/no-sync-scripts': 'warn',
45
+ '@next/next/no-title-in-document-head': 'warn',
46
+ '@next/next/no-typos': 'warn',
47
+ '@next/next/no-unwanted-polyfillio': 'warn',
48
48
  // errors
49
- "@next/next/inline-script-id": "error",
50
- "@next/next/no-assign-module-variable": "error",
51
- "@next/next/no-document-import-in-page": "error",
52
- "@next/next/no-duplicate-head": "error",
53
- "@next/next/no-head-import-in-document": "error",
54
- "@next/next/no-script-component-in-head": "error"
49
+ '@next/next/inline-script-id': 'error',
50
+ '@next/next/no-assign-module-variable': 'error',
51
+ '@next/next/no-document-import-in-page': 'error',
52
+ '@next/next/no-duplicate-head': 'error',
53
+ '@next/next/no-head-import-in-document': 'error',
54
+ '@next/next/no-script-component-in-head': 'error'
55
55
  }
56
56
  },
57
- "core-web-vitals": {
57
+ 'core-web-vitals': {
58
58
  plugins: [
59
- "@next/next"
59
+ '@next/next'
60
60
  ],
61
61
  extends: [
62
- "plugin:@next/next/recommended"
62
+ 'plugin:@next/next/recommended'
63
63
  ],
64
64
  rules: {
65
- "@next/next/no-html-link-for-pages": "error",
66
- "@next/next/no-sync-scripts": "error"
65
+ '@next/next/no-html-link-for-pages': 'error',
66
+ '@next/next/no-sync-scripts': 'error'
67
67
  }
68
68
  }
69
69
  }
@@ -6,36 +6,36 @@ function _interop_require_default(obj) {
6
6
  default: obj
7
7
  };
8
8
  }
9
- var url = "https://nextjs.org/docs/messages/google-font-display";
9
+ var url = 'https://nextjs.org/docs/messages/google-font-display';
10
10
  module.exports = (0, _definerule.defineRule)({
11
11
  meta: {
12
12
  docs: {
13
- description: "Enforce font-display behavior with Google Fonts.",
13
+ description: 'Enforce font-display behavior with Google Fonts.',
14
14
  recommended: true,
15
15
  url: url
16
16
  },
17
- type: "problem",
17
+ type: 'problem',
18
18
  schema: []
19
19
  },
20
20
  create: function create(context) {
21
21
  return {
22
22
  JSXOpeningElement: function JSXOpeningElement(node) {
23
23
  var message;
24
- if (node.name.name !== "link") {
24
+ if (node.name.name !== 'link') {
25
25
  return;
26
26
  }
27
27
  var attributes = new _nodeattributes.default(node);
28
- if (!attributes.has("href") || !attributes.hasValue("href")) {
28
+ if (!attributes.has('href') || !attributes.hasValue('href')) {
29
29
  return;
30
30
  }
31
- var hrefValue = attributes.value("href");
32
- var isGoogleFont = typeof hrefValue === "string" && hrefValue.startsWith("https://fonts.googleapis.com/css");
31
+ var hrefValue = attributes.value('href');
32
+ var isGoogleFont = typeof hrefValue === 'string' && hrefValue.startsWith('https://fonts.googleapis.com/css');
33
33
  if (isGoogleFont) {
34
- var params = new URLSearchParams(hrefValue.split("?", 2)[1]);
35
- var displayValue = params.get("display");
36
- if (!params.has("display")) {
37
- message = "A font-display parameter is missing (adding `&display=optional` is recommended).";
38
- } else if (displayValue === "auto" || displayValue === "block" || displayValue === "fallback") {
34
+ var params = new URLSearchParams(hrefValue.split('?', 2)[1]);
35
+ var displayValue = params.get('display');
36
+ if (!params.has('display')) {
37
+ message = 'A font-display parameter is missing (adding `&display=optional` is recommended).';
38
+ } else if (displayValue === 'auto' || displayValue === 'block' || displayValue === 'fallback') {
39
39
  message = "".concat(displayValue[0].toUpperCase() + displayValue.slice(1), " is not recommended.");
40
40
  }
41
41
  }
@@ -6,30 +6,30 @@ function _interop_require_default(obj) {
6
6
  default: obj
7
7
  };
8
8
  }
9
- var url = "https://nextjs.org/docs/messages/google-font-preconnect";
9
+ var url = 'https://nextjs.org/docs/messages/google-font-preconnect';
10
10
  module.exports = (0, _definerule.defineRule)({
11
11
  meta: {
12
12
  docs: {
13
- description: "Ensure `preconnect` is used with Google Fonts.",
13
+ description: 'Ensure `preconnect` is used with Google Fonts.',
14
14
  recommended: true,
15
15
  url: url
16
16
  },
17
- type: "problem",
17
+ type: 'problem',
18
18
  schema: []
19
19
  },
20
20
  create: function create(context) {
21
21
  return {
22
22
  JSXOpeningElement: function JSXOpeningElement(node) {
23
- if (node.name.name !== "link") {
23
+ if (node.name.name !== 'link') {
24
24
  return;
25
25
  }
26
26
  var attributes = new _nodeattributes.default(node);
27
- if (!attributes.has("href") || !attributes.hasValue("href")) {
27
+ if (!attributes.has('href') || !attributes.hasValue('href')) {
28
28
  return;
29
29
  }
30
- var hrefValue = attributes.value("href");
31
- var preconnectMissing = !attributes.has("rel") || !attributes.hasValue("rel") || attributes.value("rel") !== "preconnect";
32
- if (typeof hrefValue === "string" && hrefValue.startsWith("https://fonts.gstatic.com") && preconnectMissing) {
30
+ var hrefValue = attributes.value('href');
31
+ var preconnectMissing = !attributes.has('rel') || !attributes.hasValue('rel') || attributes.value('rel') !== 'preconnect';
32
+ if (typeof hrefValue === 'string' && hrefValue.startsWith('https://fonts.gstatic.com') && preconnectMissing) {
33
33
  context.report({
34
34
  node: node,
35
35
  message: '`rel="preconnect"` is missing from Google Font. See: '.concat(url)
@@ -1,21 +1,21 @@
1
1
  "use strict";
2
2
  var _definerule = require("../utils/define-rule");
3
- var url = "https://nextjs.org/docs/messages/inline-script-id";
3
+ var url = 'https://nextjs.org/docs/messages/inline-script-id';
4
4
  module.exports = (0, _definerule.defineRule)({
5
5
  meta: {
6
6
  docs: {
7
- description: "Enforce `id` attribute on `next/script` components with inline content.",
7
+ description: 'Enforce `id` attribute on `next/script` components with inline content.',
8
8
  recommended: true,
9
9
  url: url
10
10
  },
11
- type: "problem",
11
+ type: 'problem',
12
12
  schema: []
13
13
  },
14
14
  create: function create(context) {
15
15
  var nextScriptImportName = null;
16
16
  return {
17
17
  ImportDeclaration: function ImportDeclaration(node) {
18
- if (node.source.value === "next/script") {
18
+ if (node.source.value === 'next/script') {
19
19
  nextScriptImportName = node.specifiers[0].local.name;
20
20
  }
21
21
  },
@@ -29,9 +29,9 @@ module.exports = (0, _definerule.defineRule)({
29
29
  node.openingElement.attributes.forEach(function(attribute) {
30
30
  // Early return if we already have a non-checkable spread attribute, for better performance
31
31
  if (hasNonCheckableSpreadAttribute) return;
32
- if (attribute.type === "JSXAttribute") {
32
+ if (attribute.type === 'JSXAttribute') {
33
33
  attributeNames.add(attribute.name.name);
34
- } else if (attribute.type === "JSXSpreadAttribute") {
34
+ } else if (attribute.type === 'JSXSpreadAttribute') {
35
35
  if (attribute.argument && attribute.argument.properties) {
36
36
  attribute.argument.properties.forEach(function(property) {
37
37
  attributeNames.add(property.key.name);
@@ -45,8 +45,8 @@ module.exports = (0, _definerule.defineRule)({
45
45
  // https://github.com/vercel/next.js/issues/34030
46
46
  // If there is a non-checkable spread attribute, we simply ignore them
47
47
  if (hasNonCheckableSpreadAttribute) return;
48
- if (node.children.length > 0 || attributeNames.has("dangerouslySetInnerHTML")) {
49
- if (!attributeNames.has("id")) {
48
+ if (node.children.length > 0 || attributeNames.has('dangerouslySetInnerHTML')) {
49
+ if (!attributeNames.has('id')) {
50
50
  context.report({
51
51
  node: node,
52
52
  message: "`next/script` components with inline content must specify an `id` attribute. See: ".concat(url)
@@ -7,15 +7,15 @@ function _interop_require_default(obj) {
7
7
  };
8
8
  }
9
9
  var SUPPORTED_SRCS = [
10
- "www.google-analytics.com/analytics.js",
11
- "www.googletagmanager.com/gtag/js"
10
+ 'www.google-analytics.com/analytics.js',
11
+ 'www.googletagmanager.com/gtag/js'
12
12
  ];
13
13
  var SUPPORTED_HTML_CONTENT_URLS = [
14
- "www.google-analytics.com/analytics.js",
15
- "www.googletagmanager.com/gtm.js"
14
+ 'www.google-analytics.com/analytics.js',
15
+ 'www.googletagmanager.com/gtm.js'
16
16
  ];
17
- var description = "Prefer `next/script` component when using the inline script for Google Analytics.";
18
- var url = "https://nextjs.org/docs/messages/next-script-for-ga";
17
+ var description = 'Prefer `next/script` component when using the inline script for Google Analytics.';
18
+ var url = 'https://nextjs.org/docs/messages/next-script-for-ga';
19
19
  var ERROR_MSG = "".concat(description, " See: ").concat(url);
20
20
  // Check if one of the items in the list is a substring of the passed string
21
21
  var containsStr = function(str, strList) {
@@ -30,13 +30,13 @@ module.exports = (0, _definerule.defineRule)({
30
30
  recommended: true,
31
31
  url: url
32
32
  },
33
- type: "problem",
33
+ type: 'problem',
34
34
  schema: []
35
35
  },
36
36
  create: function create(context) {
37
37
  return {
38
38
  JSXOpeningElement: function JSXOpeningElement(node) {
39
- if (node.name.name !== "script") {
39
+ if (node.name.name !== 'script') {
40
40
  return;
41
41
  }
42
42
  if (node.attributes.length === 0) {
@@ -46,7 +46,7 @@ module.exports = (0, _definerule.defineRule)({
46
46
  // Check if the Alternative async tag is being used to add GA.
47
47
  // https://developers.google.com/analytics/devguides/collection/analyticsjs#alternative_async_tag
48
48
  // https://developers.google.com/analytics/devguides/collection/gtagjs
49
- if (typeof attributes.value("src") === "string" && containsStr(attributes.value("src"), SUPPORTED_SRCS)) {
49
+ if (typeof attributes.value('src') === 'string' && containsStr(attributes.value('src'), SUPPORTED_SRCS)) {
50
50
  return context.report({
51
51
  node: node,
52
52
  message: ERROR_MSG
@@ -55,8 +55,8 @@ module.exports = (0, _definerule.defineRule)({
55
55
  // Check if inline script is being used to add GA.
56
56
  // https://developers.google.com/analytics/devguides/collection/analyticsjs#the_google_analytics_tag
57
57
  // https://developers.google.com/tag-manager/quickstart
58
- if (attributes.value("dangerouslySetInnerHTML") && attributes.value("dangerouslySetInnerHTML").length > 0) {
59
- var htmlContent = attributes.value("dangerouslySetInnerHTML")[0].value.quasis && attributes.value("dangerouslySetInnerHTML")[0].value.quasis[0].value.raw;
58
+ if (attributes.value('dangerouslySetInnerHTML') && attributes.value('dangerouslySetInnerHTML').length > 0) {
59
+ var htmlContent = attributes.value('dangerouslySetInnerHTML')[0].value.quasis && attributes.value('dangerouslySetInnerHTML')[0].value.quasis[0].value.raw;
60
60
  if (htmlContent && containsStr(htmlContent, SUPPORTED_HTML_CONTENT_URLS)) {
61
61
  context.report({
62
62
  node: node,
@@ -1,14 +1,14 @@
1
1
  "use strict";
2
2
  var _definerule = require("../utils/define-rule");
3
- var url = "https://nextjs.org/docs/messages/no-assign-module-variable";
3
+ var url = 'https://nextjs.org/docs/messages/no-assign-module-variable';
4
4
  module.exports = (0, _definerule.defineRule)({
5
5
  meta: {
6
6
  docs: {
7
- description: "Prevent assignment to the `module` variable.",
7
+ description: 'Prevent assignment to the `module` variable.',
8
8
  recommended: true,
9
9
  url: url
10
10
  },
11
- type: "problem",
11
+ type: 'problem',
12
12
  schema: []
13
13
  },
14
14
  create: function create(context) {
@@ -16,8 +16,8 @@ module.exports = (0, _definerule.defineRule)({
16
16
  VariableDeclaration: function VariableDeclaration(node) {
17
17
  // Checks node.declarations array for variable with id.name of `module`
18
18
  var moduleVariableFound = node.declarations.some(function(declaration) {
19
- if ("name" in declaration.id) {
20
- return declaration.id.name === "module";
19
+ if ('name' in declaration.id) {
20
+ return declaration.id.name === 'module';
21
21
  }
22
22
  return false;
23
23
  });
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  var _definerule = require("../utils/define-rule");
3
- var url = "https://nextjs.org/docs/messages/no-async-client-component";
4
- var description = "Prevent client components from being async functions.";
3
+ var url = 'https://nextjs.org/docs/messages/no-async-client-component';
4
+ var description = 'Prevent client components from being async functions.';
5
5
  var message = "".concat(description, " See: ").concat(url);
6
6
  function isCapitalized(str) {
7
7
  return /[A-Z]/.test(str === null || str === void 0 ? void 0 : str[0]);
@@ -13,7 +13,7 @@ module.exports = (0, _definerule.defineRule)({
13
13
  recommended: true,
14
14
  url: url
15
15
  },
16
- type: "problem",
16
+ type: 'problem',
17
17
  schema: []
18
18
  },
19
19
  create: function create(context) {
@@ -24,42 +24,42 @@ module.exports = (0, _definerule.defineRule)({
24
24
  try {
25
25
  var _loop = function() {
26
26
  var block = _step.value;
27
- if (block.type === "ExpressionStatement" && block.expression.type === "Literal" && block.expression.value === "use client") {
27
+ if (block.type === 'ExpressionStatement' && block.expression.type === 'Literal' && block.expression.value === 'use client') {
28
28
  isClientComponent = true;
29
29
  }
30
- if (block.type === "ExportDefaultDeclaration" && isClientComponent) {
30
+ if (block.type === 'ExportDefaultDeclaration' && isClientComponent) {
31
31
  var _block_declaration;
32
32
  // export default async function MyComponent() {...}
33
- if (((_block_declaration = block.declaration) === null || _block_declaration === void 0 ? void 0 : _block_declaration.type) === "FunctionDeclaration" && block.declaration.async && isCapitalized(block.declaration.id.name)) {
33
+ if (((_block_declaration = block.declaration) === null || _block_declaration === void 0 ? void 0 : _block_declaration.type) === 'FunctionDeclaration' && block.declaration.async && isCapitalized(block.declaration.id.name)) {
34
34
  context.report({
35
35
  node: block,
36
36
  message: message
37
37
  });
38
38
  }
39
39
  // async function MyComponent() {...}; export default MyComponent;
40
- if (block.declaration.type === "Identifier" && isCapitalized(block.declaration.name)) {
40
+ if (block.declaration.type === 'Identifier' && isCapitalized(block.declaration.name)) {
41
41
  var targetName = block.declaration.name;
42
42
  var functionDeclaration = node.body.find(function(localBlock) {
43
- if (localBlock.type === "FunctionDeclaration" && localBlock.id.name === targetName) return true;
44
- if (localBlock.type === "VariableDeclaration" && localBlock.declarations.find(function(declaration) {
43
+ if (localBlock.type === 'FunctionDeclaration' && localBlock.id.name === targetName) return true;
44
+ if (localBlock.type === 'VariableDeclaration' && localBlock.declarations.find(function(declaration) {
45
45
  var _declaration_id;
46
- return ((_declaration_id = declaration.id) === null || _declaration_id === void 0 ? void 0 : _declaration_id.type) === "Identifier" && declaration.id.name === targetName;
46
+ return ((_declaration_id = declaration.id) === null || _declaration_id === void 0 ? void 0 : _declaration_id.type) === 'Identifier' && declaration.id.name === targetName;
47
47
  })) return true;
48
48
  return false;
49
49
  });
50
- if ((functionDeclaration === null || functionDeclaration === void 0 ? void 0 : functionDeclaration.type) === "FunctionDeclaration" && functionDeclaration.async) {
50
+ if ((functionDeclaration === null || functionDeclaration === void 0 ? void 0 : functionDeclaration.type) === 'FunctionDeclaration' && functionDeclaration.async) {
51
51
  context.report({
52
52
  node: functionDeclaration,
53
53
  message: message
54
54
  });
55
55
  }
56
- if ((functionDeclaration === null || functionDeclaration === void 0 ? void 0 : functionDeclaration.type) === "VariableDeclaration") {
56
+ if ((functionDeclaration === null || functionDeclaration === void 0 ? void 0 : functionDeclaration.type) === 'VariableDeclaration') {
57
57
  var _varDeclarator_init;
58
58
  var varDeclarator = functionDeclaration.declarations.find(function(declaration) {
59
59
  var _declaration_id;
60
- return ((_declaration_id = declaration.id) === null || _declaration_id === void 0 ? void 0 : _declaration_id.type) === "Identifier" && declaration.id.name === targetName;
60
+ return ((_declaration_id = declaration.id) === null || _declaration_id === void 0 ? void 0 : _declaration_id.type) === 'Identifier' && declaration.id.name === targetName;
61
61
  });
62
- if ((varDeclarator === null || varDeclarator === void 0 ? void 0 : (_varDeclarator_init = varDeclarator.init) === null || _varDeclarator_init === void 0 ? void 0 : _varDeclarator_init.type) === "ArrowFunctionExpression" && varDeclarator.init.async) {
62
+ if ((varDeclarator === null || varDeclarator === void 0 ? void 0 : (_varDeclarator_init = varDeclarator.init) === null || _varDeclarator_init === void 0 ? void 0 : _varDeclarator_init.type) === 'ArrowFunctionExpression' && varDeclarator.init.async) {
63
63
  context.report({
64
64
  node: functionDeclaration,
65
65
  message: message
@@ -42,7 +42,7 @@ function _interop_require_wildcard(obj, nodeInterop) {
42
42
  }
43
43
  return newObj;
44
44
  }
45
- var url = "https://nextjs.org/docs/messages/no-before-interactive-script-outside-document";
45
+ var url = 'https://nextjs.org/docs/messages/no-before-interactive-script-outside-document';
46
46
  var convertToCorrectSeparator = function(str) {
47
47
  return str.replace(/[\\/]/g, _path.sep);
48
48
  };
@@ -53,7 +53,7 @@ module.exports = (0, _definerule.defineRule)({
53
53
  recommended: true,
54
54
  url: url
55
55
  },
56
- type: "problem",
56
+ type: 'problem',
57
57
  schema: []
58
58
  },
59
59
  create: function create(context) {
@@ -63,7 +63,7 @@ module.exports = (0, _definerule.defineRule)({
63
63
  scriptImportName = node.local.name;
64
64
  },
65
65
  JSXOpeningElement: function JSXOpeningElement(node) {
66
- var pathname = convertToCorrectSeparator(context.getFilename());
66
+ var pathname = convertToCorrectSeparator(context.filename);
67
67
  var isInAppDir = pathname.includes("".concat(_path.sep, "app").concat(_path.sep));
68
68
  // This rule shouldn't fire in `app/`
69
69
  if (isInAppDir) {
@@ -76,13 +76,13 @@ module.exports = (0, _definerule.defineRule)({
76
76
  return;
77
77
  }
78
78
  var strategy = node.attributes.find(function(child) {
79
- return child.name && child.name.name === "strategy";
79
+ return child.name && child.name.name === 'strategy';
80
80
  });
81
- if (!strategy || !strategy.value || strategy.value.value !== "beforeInteractive") {
81
+ if (!strategy || !strategy.value || strategy.value.value !== 'beforeInteractive') {
82
82
  return;
83
83
  }
84
- var document = context.getFilename().split("pages", 2)[1];
85
- if (document && _path.parse(document).name.startsWith("_document")) {
84
+ var document = context.filename.split('pages', 2)[1];
85
+ if (document && _path.parse(document).name.startsWith('_document')) {
86
86
  return;
87
87
  }
88
88
  context.report({
@@ -1,32 +1,32 @@
1
1
  "use strict";
2
2
  var _definerule = require("../utils/define-rule");
3
- var url = "https://nextjs.org/docs/messages/no-css-tags";
3
+ var url = 'https://nextjs.org/docs/messages/no-css-tags';
4
4
  module.exports = (0, _definerule.defineRule)({
5
5
  meta: {
6
6
  docs: {
7
- description: "Prevent manual stylesheet tags.",
7
+ description: 'Prevent manual stylesheet tags.',
8
8
  recommended: true,
9
9
  url: url
10
10
  },
11
- type: "problem",
11
+ type: 'problem',
12
12
  schema: []
13
13
  },
14
14
  create: function create(context) {
15
15
  return {
16
16
  JSXOpeningElement: function JSXOpeningElement(node) {
17
- if (node.name.name !== "link") {
17
+ if (node.name.name !== 'link') {
18
18
  return;
19
19
  }
20
20
  if (node.attributes.length === 0) {
21
21
  return;
22
22
  }
23
23
  var attributes = node.attributes.filter(function(attr) {
24
- return attr.type === "JSXAttribute";
24
+ return attr.type === 'JSXAttribute';
25
25
  });
26
26
  if (attributes.find(function(attr) {
27
- return attr.name.name === "rel" && attr.value.value === "stylesheet";
27
+ return attr.name.name === 'rel' && attr.value.value === 'stylesheet';
28
28
  }) && attributes.find(function(attr) {
29
- return attr.name.name === "href" && attr.value.type === "Literal" && !/^https?/.test(attr.value.value);
29
+ return attr.name.name === 'href' && attr.value.type === 'Literal' && !/^https?/.test(attr.value.value);
30
30
  })) {
31
31
  context.report({
32
32
  node: node,
@@ -42,24 +42,24 @@ function _interop_require_wildcard(obj, nodeInterop) {
42
42
  }
43
43
  return newObj;
44
44
  }
45
- var url = "https://nextjs.org/docs/messages/no-document-import-in-page";
45
+ var url = 'https://nextjs.org/docs/messages/no-document-import-in-page';
46
46
  module.exports = (0, _definerule.defineRule)({
47
47
  meta: {
48
48
  docs: {
49
- description: "Prevent importing `next/document` outside of `pages/_document.js`.",
49
+ description: 'Prevent importing `next/document` outside of `pages/_document.js`.',
50
50
  recommended: true,
51
51
  url: url
52
52
  },
53
- type: "problem",
53
+ type: 'problem',
54
54
  schema: []
55
55
  },
56
56
  create: function create(context) {
57
57
  return {
58
58
  ImportDeclaration: function ImportDeclaration(node) {
59
- if (node.source.value !== "next/document") {
59
+ if (node.source.value !== 'next/document') {
60
60
  return;
61
61
  }
62
- var paths = context.getFilename().split("pages");
62
+ var paths = context.filename.split('pages');
63
63
  var page = paths[paths.length - 1];
64
64
  if (!page || page.startsWith("".concat(_path.sep, "_document")) || page.startsWith("".concat(_path.posix.sep, "_document"))) {
65
65
  return;
@@ -1,24 +1,25 @@
1
1
  "use strict";
2
2
  var _definerule = require("../utils/define-rule");
3
- var url = "https://nextjs.org/docs/messages/no-duplicate-head";
3
+ var url = 'https://nextjs.org/docs/messages/no-duplicate-head';
4
4
  module.exports = (0, _definerule.defineRule)({
5
5
  meta: {
6
6
  docs: {
7
- description: "Prevent duplicate usage of `<Head>` in `pages/_document.js`.",
7
+ description: 'Prevent duplicate usage of `<Head>` in `pages/_document.js`.',
8
8
  recommended: true,
9
9
  url: url
10
10
  },
11
- type: "problem",
11
+ type: 'problem',
12
12
  schema: []
13
13
  },
14
14
  create: function create(context) {
15
+ var sourceCode = context.sourceCode;
15
16
  var documentImportName;
16
17
  return {
17
18
  ImportDeclaration: function ImportDeclaration(node) {
18
- if (node.source.value === "next/document") {
19
+ if (node.source.value === 'next/document') {
19
20
  var documentImport = node.specifiers.find(function(param) {
20
21
  var type = param.type;
21
- return type === "ImportDefaultSpecifier";
22
+ return type === 'ImportDefaultSpecifier';
22
23
  });
23
24
  if (documentImport && documentImport.local) {
24
25
  documentImportName = documentImport.local.name;
@@ -26,18 +27,17 @@ module.exports = (0, _definerule.defineRule)({
26
27
  }
27
28
  },
28
29
  ReturnStatement: function ReturnStatement(node) {
29
- var ancestors = context.getAncestors();
30
+ var ancestors = sourceCode.getAncestors(node);
30
31
  var documentClass = ancestors.find(function(ancestorNode) {
31
- return ancestorNode.type === "ClassDeclaration" && ancestorNode.superClass && "name" in ancestorNode.superClass && ancestorNode.superClass.name === documentImportName;
32
+ return ancestorNode.type === 'ClassDeclaration' && ancestorNode.superClass && 'name' in ancestorNode.superClass && ancestorNode.superClass.name === documentImportName;
32
33
  });
33
34
  if (!documentClass) {
34
35
  return;
35
36
  }
36
- // @ts-expect-error - `node.argument` could be a `JSXElement` which has property `children`
37
- if (node.argument && "children" in node.argument && node.argument.children) {
37
+ if (node.argument && 'children' in node.argument && node.argument.children) {
38
38
  // @ts-expect-error - `node.argument` could be a `JSXElement` which has property `children`
39
39
  var headComponents = node.argument.children.filter(function(childrenNode) {
40
- return childrenNode.openingElement && childrenNode.openingElement.name && childrenNode.openingElement.name.name === "Head";
40
+ return childrenNode.openingElement && childrenNode.openingElement.name && childrenNode.openingElement.name.name === 'Head';
41
41
  });
42
42
  if (headComponents.length > 1) {
43
43
  for(var i = 1; i < headComponents.length; i++){