no-assign-module-variable.js 828 B

12345678910111213141516171819202122232425262728293031323334
  1. const url = 'https://nextjs.org/docs/messages/no-assign-module-variable'
  2. module.exports = {
  3. meta: {
  4. docs: {
  5. description: 'Prevent assignment to the `module` variable.',
  6. recommended: true,
  7. url,
  8. },
  9. type: 'problem',
  10. schema: [],
  11. },
  12. create: function (context) {
  13. return {
  14. VariableDeclaration(node) {
  15. // Checks node.declarations array for variable with id.name of `module`
  16. const moduleVariableFound = node.declarations.some(
  17. (declaration) => declaration.id.name === 'module'
  18. )
  19. // Return early if no `module` variable is found
  20. if (!moduleVariableFound) {
  21. return
  22. }
  23. context.report({
  24. node,
  25. message: `Do not assign to the variable \`module\`. See: ${url}`,
  26. })
  27. },
  28. }
  29. },
  30. }