cletusw / eslint-plugin-local-rules

A plugin for ESLint that allows you to use project-specific rules
MIT License
158 stars 9 forks source link

fix/add-error-message-for-other-module-not-found #8

Closed JohnDaly closed 2 years ago

JohnDaly commented 2 years ago

If there is a require statement in the 'eslint-local-rules' file, which results in a MODULE_NOT_FOUND error, its not immediately obvious with the current error messaging.

// eslint-local-rules.js

// Will cause a 'MODULE_NOT_FOUND' error
require('bad-import-which-will-not-resolve');

module.exports = {
  'disallow-identifiers': {
    meta: {
      docs: {
        description: 'disallow identifiers',
        category: 'Possible Errors',
        recommended: false,
      },
      schema: [],
    },
    create: function(context) {
      return {
        Identifier: function(node) {
          context.report({
            node: node,
            message: 'Identifiers not allowed for Super Important reasons.',
          });
        },
      };
    },
  },
};

Will result in the following error:

 Error: eslint-plugin-local-rules: Cannot find "eslint-local-rules{.js,.cjs} or eslint-local-rules/index.js (checked all
    ancestors of "path/to/eslint-plugin-local-rules").

This PR will make it so that the Cannot find module 'bad-import-which-will-not-resolve' error will be thrown

cletusw commented 2 years ago

Great find & fix! I simplified the code a little -- let me know if it's still good and I'll get it merged, thanks!

JohnDaly commented 2 years ago

Great find & fix! I simplified the code a little -- let me know if it's still good and I'll get it merged, thanks!

Looks great!

cletusw commented 2 years ago

Merged and released v1.1.1, thanks for the fix!

diegocr commented 2 years ago

Guys, I think this PR is causing the issue pointed in #7 since i never encountered it before with 1.1.0

Error: Failed to load plugin 'local-rules' declared in '.eslintrc.json': eslint-plugin-local-rules: Cannot find "eslint-local-rules{.js,.cjs} or eslint-local-rules/index.js (...).

Noteworthy, i don't have any require() call into my eslint-local-rules.js

Can you please look at fixing this at your earliest convenience? Thanks in advance!

cletusw commented 2 years ago

@diegocr Sorry about that!! I was literally just thinking how bad it is this thing doesn't have a single test. Reverted this changed and published as v1.1.2. I'll try again more carefully -- if you have a simplified version of your setup that errors in v1.1.1 that I can test against that would be great, thanks.