Working together, both rules will produces exports such as:
export { a, b, c};
📖 Examples
The following patterns are considered problems:
const a = 1; const b = 2; const c = 3; export { a, b, c };// Message: undefined// Message: undefinedconst a = 1; const b = 2; const c = 3; export { a, b, c, };// Message: undefined// Message: undefinedconst a = 1; const b = 2; export { a as default, b }// Message: undefined
The following patterns are not considered problems:
export { a,b,c } from 'foo'const a = 1; const b = 2; const c = 3; export { a,b,c };export * from 'foo'
filename-match-exported
Match the file name against the default exported value in the module. Files that don't have a default export will be ignored. The exports of index.js are matched against their parent directory.
// Considered problem only if the file isn't named foo.js or foo/index.jsexport default function foo() {}// Considered problem only if the file isn't named Foo.js or Foo/index.jsmodule.exports = class Foo() {}// Considered problem only if the file isn't named someVariable.js or someVariable/index.jsmodule.exports = someVariable;// Never considered a problemexport default { foo: "bar" };
If your filename policy doesn't quite match with your variable naming policy, you can add one or multiple transforms:
If you prefer to use suffixes for your files (e.g. Foo.react.js for a React component file), you can use a second configuration parameter. It allows you to remove parts of a filename matching a regex pattern before transforming and matching against the export.
Enforce a certain file naming convention using a regular expression.
The convention can be configured using a regular expression (the default is camelCase.js). Additionally
exporting files can be ignored with a second configuration parameter.
With these configuration options, camelCase.js will be reported as an error while snake_case.js will pass.
Additionally the files that have a named default export (according to the logic in the match-exported rule) will be
ignored. They could be linted with the match-exported rule. Please note that exported function calls are not
respected in this case.
📖 Examples
The following patterns are considered problems:
Having a bunch of index.js files can have negative influence on developer experience, e.g. when
opening files by name. When enabling this rule. index.js files will always be considered a problem.
📖 Examples
The following patterns are considered problems:
📖 Examples
The following patterns are considered problems:
// Settings: {"import/parsers":{"@typescript-eslint/parser":[".ts",".tsx"]},"import/resolver":{"typescript":{"project":"<baseDir>/tests/fixtures/noBarrelImport/invalid/barrelImport/tsconfig.json"}}}import { foo } from './bar';// Message: undefined// Settings: {"import/parsers":{"@typescript-eslint/parser":[".ts",".tsx"]},"import/resolver":{"typescript":{"project":"<baseDir>/tests/fixtures/noBarrelImport/invalid/barrelImportAliased/tsconfig.json"}}}import { foo as FOO } from './bar';// Message: undefined// Settings: {"import/parsers":{"@typescript-eslint/parser":[".ts",".tsx"]},"import/resolver":{"typescript":{"project":"<baseDir>/tests/fixtures/noBarrelImport/invalid/barrelImportAliasedReexport/tsconfig.json"}}}import { bar } from './bar';// Message: undefined// Settings: {"import/parsers":{"@typescript-eslint/parser":[".ts",".tsx"]},"import/resolver":{"typescript":{"project":"<baseDir>/tests/fixtures/noBarrelImport/invalid/barrelImportDeep/tsconfig.json"}}}import { foo } from './baz';// Message: undefined// Settings: {"import/parsers":{"@typescript-eslint/parser":[".ts",".tsx"]},"import/resolver":{"typescript":{"project":"<baseDir>/tests/fixtures/noBarrelImport/invalid/barrelImportDefault/tsconfig.json"}}}import foo from './bar';// Message: undefined// Settings: {"import/parsers":{"@typescript-eslint/parser":[".ts",".tsx"]},"import/resolver":{"typescript":{"project":"<baseDir>/tests/fixtures/noBarrelImport/invalid/barrelTypeImport/tsconfig.json"}}}import { type Foo } from './bar';// Message: undefined// Settings: {"import/parsers":{"@typescript-eslint/parser":[".ts",".tsx"]},"import/resolver":{"typescript":{"project":"<baseDir>/tests/fixtures/noBarrelImport/invalid/mixedImport/tsconfig.json"}}}import { foo, bar } from './bar';// Message: undefined
The following patterns are not considered problems:
// Settings: {"import/parsers":{"@typescript-eslint/parser":[".ts",".tsx"]},"import/resolver":{"typescript":{"project":"<baseDir>/tests/fixtures/noBarrelImport/valid/directImport/tsconfig.json"}}}import { foo } from './foo';// Settings: {"import/parsers":{"@typescript-eslint/parser":[".ts",".tsx"]},"import/resolver":{"typescript":{"project":"<baseDir>/tests/fixtures/noBarrelImport/valid/directImportDefault/tsconfig.json"}}}import foo from './foo';// Settings: {"import/parsers":{"@typescript-eslint/parser":[".ts",".tsx"]},"import/resolver":{"typescript":{"project":"<baseDir>/tests/fixtures/noBarrelImport/valid/packageImport/tsconfig.json"}}}import { logLevels } from 'roarr';
no-export-all
The --fix option on the command line automatically fixes problems reported by this rule.
Requite that re-exports are named.
📖 Examples
The following patterns are considered problems:
// Settings: {"import/parsers":{"@typescript-eslint/parser":[".ts",".tsx"]},"import/resolver":{"typescript":{"project":"<baseDir>/tests/fixtures/noExportAll/invalid/namespaceExport/tsconfig.json"}}}export * from './foo';// Message: undefined// Settings: {"import/parsers":{"@typescript-eslint/parser":[".ts",".tsx"]},"import/resolver":{"typescript":{"project":"<baseDir>/tests/fixtures/noExportAll/invalid/reExport/tsconfig.json"}}}export * from './foo';// Message: undefined
The following patterns are not considered problems:
// Settings: {"import/parsers":{"@typescript-eslint/parser":[".ts",".tsx"]},"import/resolver":{"typescript":{"project":"<baseDir>/tests/fixtures/noExportAll/valid/namedExport/tsconfig.json"}}}export { FOO } from './foo';// Settings: {"import/parsers":{"@typescript-eslint/parser":[".ts",".tsx"]},"import/resolver":{"typescript":{"project":"<baseDir>/tests/fixtures/noExportAll/valid/aliasedReExport/tsconfig.json"}}}export * as foo from './foo';
no-import-namespace-destructure
Disallows the practice of importing an entire module's namespace using import * as Namespace and then destructuring specific exports from it. Instead, it encourages direct importing of only the necessary named exports from a module.
📖 Examples
The following patterns are considered problems:
import * as bar from 'bar'; const { foo } = bar;// Message: undefined
The following patterns are not considered problems:
import * as bar from 'bar'
no-re-export
Disallows re-exports of imports.
📖 Examples
The following patterns are considered problems:
import Button1 from 'app/CustomButton'; export const CustomButton = Button1;// Message: undefined import { Button as CustomButton2 } from 'app/CustomButton'; export const CustomButton = CustomButton2;// Message: undefined import * as Button3 from "app/Button"; export const CustomButton = Button3;// Message: undefined import Button4 from 'app/CustomButton'; export default Button4;// Message: undefined export { default as Button5 } from 'app/CustomButton';// Message: undefined import Button6 from 'app/CustomButton'; export { Button6 };// Message: undefined import Button7 from 'app/CustomButton'; export const Buttons = { Button: Button7 };// Message: undefined import Button8 from 'app/CustomButton'; export default Button8; export { Button8 }// Message: undefined// Message: undefined export * from 'app/CustomButton';// Message: undefined
Restricts re-assigning imports to variables that are exported.
📖 Examples
The following patterns are considered problems:
import { Foo } from './Foo';export const Bar = { Foo,};// Message: undefinedimport { Foo } from './Foo';export default { Foo,};// Message: undefined
no-restricted-imports
Disallow specified modules when loaded by import
This rule is similar to no-restricted-imports except that it allows you to specify unique messages for each restricted import (a workaround for issue issues#15261).
Note: Unlike the ESLint rule, this rule does not support the patterns option and it does not handle exports.
📖 Examples
The following patterns are considered problems:
// Options: [{"paths":[{"importName":"*","message":"foo is restricted","name":"bar"}]}]import * as bar from 'bar'// Message: undefined// Options: [{"paths":[{"importName":"foo","message":"foo is restricted","name":"bar"}]}]import { foo } from 'bar'// Message: undefined// Options: [{"paths":[{"importName":"default","message":"foo is restricted","name":"bar"}]}]import { default as bar } from 'bar'// Message: undefined// Options: [{"paths":[{"message":"foo is restricted","name":"bar"}]}]import bar from 'bar'// Message: undefined
The following patterns are not considered problems:
// Options: [{"paths":[{"importName":"foo","message":"foo is restricted","name":"bar"}]}]import { bar } from 'bar'
no-restricted-strings
Disallow specified strings.
📖 Examples
The following patterns are considered problems:
the grandfather directory is path.resolve(__dirname, 'src')
rewrite import path to use alias when
import path matches ^src\/
relative import is greater than 2
The grandfather directory is essentially whichever directory that is accessed by the doubledot (../) by the import path.
📖 Examples
The following patterns are considered problems:
// Options: [{"aliases":[{"alias":"@/a/","matchPath":"^a\\/","maxRelativeDepth":-1}],"baseDirectory":"<baseDir>/fixtures/preferImportAlias"}]import { bar } from './bar';// Message: undefined// Options: [{"aliases":[{"alias":"@/a/","matchPath":"^a\\/","maxRelativeDepth":1}],"baseDirectory":"<baseDir>/fixtures/preferImportAlias"}]import { baz } from '../baz';// Message: undefined// Options: [{"aliases":[{"alias":"@/a/","matchPath":"^a\\/"}],"baseDirectory":"<baseDir>/fixtures/preferImportAlias"}]import { bar } from '../bar';// Message: undefined
The following patterns are not considered problems:
// Options: [{"aliases":[{"alias":"@/a/","matchParent":"<baseDir>/fixtures/preferImportAlias","matchPath":"^a\\/"}],"baseDirectory":"<baseDir>/fixtures/preferImportAlias"}]import { bar } from '../bar';// Options: [{"baseDirectory":"<baseDir>/fixtures/preferImportAlias"}]import Foo from '@bar/baz';// Options: [{"baseDirectory":"<baseDir>/fixtures/preferImportAlias"}]import Foo, { Foo } from 'bar';// Options: [{"baseDirectory":"<baseDir>/fixtures/preferImportAlias"}]import { foo } from './foo';// Options: [{"baseDirectory":"<baseDir>/fixtures/preferImportAlias"}]import { foo } from '../foo';// Options: [{"baseDirectory":"<baseDir>/fixtures/preferImportAlias"}]import { foo } from '.././foo';// Options: [{"baseDirectory":"<baseDir>/fixtures/preferImportAlias"}]import { foo } from '././../foo';// Options: [{"baseDirectory":"<baseDir>/fixtures/preferImportAlias"}]import { foo } from '@bar/baz';// Options: [{"baseDirectory":"<baseDir>/fixtures/preferImportAlias"}]import { foo } from '../../foo';
prefer-inline-type-import
The --fix option on the command line automatically fixes problems reported by this rule.
TypeScript 4.5 introduced type modifiers that allow to inline type imports as opposed to having dedicated import type. This allows to remove duplicate type imports. This rule enforces use of import type modifiers.
📖 Examples
The following patterns are considered problems:
import type {foo} from 'bar'// Message: undefinedimport type {foo, baz} from 'bar'// Message: undefined
The following patterns are not considered problems:
import {type foo} from 'bar'import type Foo from 'bar'import type * as Foo from 'bar'
prefer-react-lazy
Requires that components that can be loaded lazily be imported using the React.lazy() function.
In React, it is common to use useEffect without dependencies when the intent is to run the effect only once (on mount and unmount). However, just doing that may lead to undesired side-effects, such as the effect being called twice in Strict Mode. For this reason, it is better to use an abstraction such as useMount that handles this use case.
📖 Examples
The following patterns are considered problems:
useEffect(() => {}, [])// Message: undefined
The following patterns are not considered problems:
useEffect(() => {}, [foo])useMount(() => {}, [])
require-extension
The --fix option on the command line automatically fixes problems reported by this rule.
Adds .js extension to all imports and exports.
It resolves the following cases:
Relative imports
Relative imports that resolve to a file of the same name:
import './foo'; // => import './foo.js';
Relative imports that resolve to an index file:
import './foo'; // => import './foo/index.js';
The above examples would also work if the file extension was .ts or .tsx, i.e.