Unverified Commit c83f94cf authored by Michael Novotny's avatar Michael Novotny Committed by GitHub

Readds missing `@next/next/no-assign-module-variable` ESLint rule. (#38134)

Readds `@next/next/no-assign-module-variable` ESLint rule that was inadvertently removed in #34335 during the resolution of many merge conflicts.

This PR will get us back to a good / working state. I'll see if I can add a test to ensure all rule are accounted for in a separate PR.

Fixes #34335.

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [x] Make sure the linting passes by running `pnpm lint`
- [x] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
parent 0ecbcc6d
...@@ -88,6 +88,7 @@ Next.js provides an ESLint plugin, [`eslint-plugin-next`](https://www.npmjs.com/ ...@@ -88,6 +88,7 @@ Next.js provides an ESLint plugin, [`eslint-plugin-next`](https://www.npmjs.com/
| ✔️ | [@next/next/google-font-preconnect](/docs/messages/google-font-preconnect.md) | Ensure `preconnect` is used with Google Fonts. | | ✔️ | [@next/next/google-font-preconnect](/docs/messages/google-font-preconnect.md) | Ensure `preconnect` is used with Google Fonts. |
| ✔️ | [@next/next/inline-script-id](/docs/messages/inline-script-id.md) | Enforce `id` attribute on `next/script` components with inline content. | | ✔️ | [@next/next/inline-script-id](/docs/messages/inline-script-id.md) | Enforce `id` attribute on `next/script` components with inline content. |
| ✔️ | [@next/next/next-script-for-ga](/docs/messages/next-script-for-ga.md) | Prefer `next/script` component when using the inline script for Google Analytics. | | ✔️ | [@next/next/next-script-for-ga](/docs/messages/next-script-for-ga.md) | Prefer `next/script` component when using the inline script for Google Analytics. |
| ✔️ | [@next/next/no-assign-module-variable](/docs/messages/no-assign-module-variable.md) | Prevent assignment to the `module` variable. |
| ✔️ | [@next/next/no-before-interactive-script-outside-document](/docs/messages/no-before-interactive-script-outside-document.md) | Prevent usage of `next/script`'s `beforeInteractive` strategy outside of `pages/_document.js`. | | ✔️ | [@next/next/no-before-interactive-script-outside-document](/docs/messages/no-before-interactive-script-outside-document.md) | Prevent usage of `next/script`'s `beforeInteractive` strategy outside of `pages/_document.js`. |
| ✔️ | [@next/next/no-css-tags](/docs/messages/no-css-tags.md) | Prevent manual stylesheet tags. | | ✔️ | [@next/next/no-css-tags](/docs/messages/no-css-tags.md) | Prevent manual stylesheet tags. |
| ✔️ | [@next/next/no-document-import-in-page](/docs/messages/no-document-import-in-page.md) | Prevent importing `next/document` outside of `pages/_document.js`. | | ✔️ | [@next/next/no-document-import-in-page](/docs/messages/no-document-import-in-page.md) | Prevent importing `next/document` outside of `pages/_document.js`. |
......
# No assign module variable # No assign module variable
> Prevent assignment to the `module` variable.
#### Why This Error Occurred #### Why This Error Occurred
A value is being assigned to the `module` variable. The `module` variable is already used and it is highly likely that assigning to this variable will cause errors. A value is being assigned to the `module` variable. The `module` variable is already used and it is highly likely that assigning to this variable will cause errors.
......
...@@ -4,6 +4,7 @@ module.exports = { ...@@ -4,6 +4,7 @@ module.exports = {
'google-font-preconnect': require('./rules/google-font-preconnect'), 'google-font-preconnect': require('./rules/google-font-preconnect'),
'inline-script-id': require('./rules/inline-script-id'), 'inline-script-id': require('./rules/inline-script-id'),
'next-script-for-ga': require('./rules/next-script-for-ga'), 'next-script-for-ga': require('./rules/next-script-for-ga'),
'no-assign-module-variable': require('./rules/no-assign-module-variable'),
'no-before-interactive-script-outside-document': require('./rules/no-before-interactive-script-outside-document'), 'no-before-interactive-script-outside-document': require('./rules/no-before-interactive-script-outside-document'),
'no-css-tags': require('./rules/no-css-tags'), 'no-css-tags': require('./rules/no-css-tags'),
'no-document-import-in-page': require('./rules/no-document-import-in-page'), 'no-document-import-in-page': require('./rules/no-document-import-in-page'),
...@@ -41,6 +42,7 @@ module.exports = { ...@@ -41,6 +42,7 @@ module.exports = {
'@next/next/no-unwanted-polyfillio': 'warn', '@next/next/no-unwanted-polyfillio': 'warn',
// errors // errors
'@next/next/inline-script-id': 'error', '@next/next/inline-script-id': 'error',
'@next/next/no-assign-module-variable': 'error',
'@next/next/no-document-import-in-page': 'error', '@next/next/no-document-import-in-page': 'error',
'@next/next/no-duplicate-head': 'error', '@next/next/no-duplicate-head': 'error',
'@next/next/no-head-import-in-document': 'error', '@next/next/no-head-import-in-document': 'error',
......
const url = 'https://nextjs.org/docs/messages/no-assign-module-variable'
module.exports = { module.exports = {
meta: { meta: {
docs: { docs: {
description: `Prohibit assignment to the 'module' variable`, description: 'Prevent assignment to the `module` variable.',
recommended: true, recommended: true,
url: 'https://nextjs.org/docs/messages/no-assign-module-variable', url,
}, },
}, },
create: function (context) { create: function (context) {
return { return {
VariableDeclaration(node) { VariableDeclaration(node) {
// Checks node.declarations array for variable with id.name of 'module' // Checks node.declarations array for variable with id.name of `module`
const moduleVariableFound = node.declarations.some( const moduleVariableFound = node.declarations.some(
(declaration) => declaration.id.name === 'module' (declaration) => declaration.id.name === 'module'
) )
// Return early if no 'module' variable is found // Return early if no `module` variable is found
if (!moduleVariableFound) { if (!moduleVariableFound) {
return return
} }
context.report({ context.report({
node, node,
message: `Do not assign to the variable 'module'. See: https://nextjs.org/docs/messages/no-assign-module-variable`, message: `Do not assign to the variable \`module\`. See: ${url}`,
}) })
}, },
} }
......
...@@ -34,7 +34,7 @@ ruleTester.run('no-assign-module-variable', rule, { ...@@ -34,7 +34,7 @@ ruleTester.run('no-assign-module-variable', rule, {
errors: [ errors: [
{ {
message: message:
"Do not assign to the variable 'module'. See: https://nextjs.org/docs/messages/no-assign-module-variable", 'Do not assign to the variable `module`. See: https://nextjs.org/docs/messages/no-assign-module-variable',
}, },
], ],
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment