'How to avoid relative imports with no-restricted-imports

What I want

I want to avoid the deep relative imports like ../../../, and I want to allow only the relative import of package.json file, so I set up the eslint no-restricted-imports rule like so:

.eslintrc.js

module.exports = {
  rules: {
    'no-restricted-imports': [
      'error',
      {
        patterns: [
          {
            group: ['**/../../*', '!**/../../package.json'],
            message: 'Please use alias instead of deep relative imports.',
          },
        ],
      },
    ],
  },
};

The problem

The problem with this configuration is that it is taking the imports from package.json as well, so this is throwing error: import * as PackageJSON from '../../../package.json';

how can I avoid all relative imports except the package.json one?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source