Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[no-restricted-path] Custom error message #1802

Merged

Conversation

malykhinvi
Copy link
Contributor

@malykhinvi malykhinvi commented Jun 6, 2020

Main change
Adds a message configuration param for every zone, that will be displayed in case of the rule violation.
The logic is pretty similar to eslint's no-restricted-imports

Background
Sometimes, it is not very clear, why you can not import certain modules in certain scenarios. This is especially the case for newcomers. To be more user friendly, we could display additional info, right in the error message. It would look something like this:

//eslint config
'import/no-restricted-paths': [
  'error',
  {
    basePath: './src',
    zones: [ {
      target: './core',
      from: './features',
      message: '' +
        '\n\nCore should be completely isolated from features.' +
        '\nFeatures may use core but not vice versa',
    }],
  }
],

Then VSCode would display it like that:
Screenshot 2020-06-06 at 13 27 11

@malykhinvi malykhinvi marked this pull request as ready for review June 6, 2020 10:43
@coveralls
Copy link

coveralls commented Jun 6, 2020

Coverage Status

Coverage remained the same at 97.708% when pulling 0b81052 on malykhinvi:no-resticted-path-custom-message into 0b585a1 on benmosher:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 97.739% when pulling 7b5e2dc on malykhinvi:no-resticted-path-custom-message into 0547c7e on benmosher:master.

2 similar comments
@coveralls
Copy link

Coverage Status

Coverage remained the same at 97.739% when pulling 7b5e2dc on malykhinvi:no-resticted-path-custom-message into 0547c7e on benmosher:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 97.739% when pulling 7b5e2dc on malykhinvi:no-resticted-path-custom-message into 0547c7e on benmosher:master.

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Straightforward, looks good. Thanks!

src/rules/no-restricted-paths.js Outdated Show resolved Hide resolved
tests/src/rules/no-restricted-paths.js Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants