eslint-plugin-import
eslint-plugin-import copied to clipboard
no-restricted-paths/ How to set except zone for the relative paths. Please can you help me 🙏🙏🙏
Good day! I have a folder structure:
my-project
|----- src
│ |----- main
| |----- api.1
| |----- ConstService.js
| |----- api.2
| |------ AccountService.js
| |----- components
| |------ ScreenLogin.js
| |------ service
| |------ workers
And I need to restrict the import from './src/main/api.1' to './src/main', but except one zone './src/main/api.2. It means only possible to import the entities from './src/main/api.1' to './src/main/api.2. Means to get the error if import the entities from './src/main/api.1' to './src/main/components', './src/main/service', and './src/main/workers/'. My rule:
'rules': {
'import/no-restricted-paths': [
'error',
{
'zones': [
{ 'target': './src/main', 'from': './src/main/api.1', 'except': ['./src/main/api.2'] },
],
}
],
},
The linted file is './src/main/components/ScreenLogin.js:
// IN THIS CASE GET THE ERROR NO-RESTRICTED-PATHS:
import { ConstService } from '../api.1'
The linted file is './src/main/api.2/AccountService.js:
// IN THIS CASE I DON'T NEED GET THE ERROR, BUT I HAVE THE ERROR:
import { AccountService } from '../api.1'
Please can you tell me how can I set the exception for './src/main/api.2' in my case. According the documentation: An optional except may be defined for a zone, allowing exception paths that would otherwise violate the related from. What does it means the exception path only can be relative to from zone. Please can you tell which way I can set in my case 🙏🙏🙏
Assuming your eslint config is in the root, this seems like it should work.
If you'd like to make a PR with a failing test case, I can try to get it working.