Skip to content

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

Merged
ljharb merged 1 commit into
import-js:masterfrom
malykhinvi:no-resticted-path-custom-message
Jun 7, 2020
Merged

[no-restricted-path] Custom error message#1802
ljharb merged 1 commit into
import-js:masterfrom
malykhinvi:no-resticted-path-custom-message

Conversation

@malykhinvi

@malykhinvi malykhinvi commented Jun 6, 2020

Copy link
Copy Markdown
Contributor

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

coveralls commented Jun 6, 2020

Copy link
Copy Markdown

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
Copy Markdown

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
Copy Markdown

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
Copy Markdown

Coverage Status

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

@ljharb ljharb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Straightforward, looks good. Thanks!

Comment thread src/rules/no-restricted-paths.js Outdated
Comment thread tests/src/rules/no-restricted-paths.js Outdated
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