@agrovista/eslint-plugin-eslint-rules v1.6.0
Agrovista Eslint Rules
A collection of custom ESLint rules used by the Agrovista development team. These are likely to be integrated with our custom eslint-config described here.
Installation
Install eslint and rules
$ yarn add -D eslint @agrovista/eslint-plugin-eslint-rules
Rules
No relative import paths
Moving a file to different folder, could result in changing all imports statement in that file. This will not happen is the import paths are absolute. The eslint rule helps enforcing having absolute import paths. Support eslint --fix to automatically change imports to absolute paths.
Configuration
Add the plugin to the plugins section, and configure the rule options.
{
"plugins": ["@agrovista/eslint-rules"],
"rules": {
"@agrovista/eslint-rules/no-relative-import-paths": [
"warn",
{ "allowSameFolder": true }
]
}
}
Rule options
"@agrovista/eslint-rules/no-relative-import-paths": [
"warn",
{ "allowSameFolder": true, "rootDir": "src", "prefix": "" }
]
enabled
: for enabling the rule. 0=off, 1=warn, 2=error. Defaults to 0.ignorePureComponents
: optional boolean set totrue
to allow relative import paths for imported files from the same folder (default tofalse
).
allowSameFolder
When true
the rule will ignore relative import paths for imported files from the same folder
Examples of code for this rule:
// when true this will be ignored
// when false this will generate a warning
import Something from "./something";
// will always generate a warning
import Something from "../modules/something";
rootDir
Useful when auto-fixing and the rootDir should not be included in the absolute path.
Examples of code for this rule:
// when not configured:
import Something from "../../components/something";
// will result in
import Something from "src/components/something";
// when configured as { "rootDir": "src" }
import Something from "../../components/something";
// will result in
import Something from "components/something";
// ^- no 'src/' prefix is added
prefix
Useful when auto-fixing and a prefix should be included in the absolute path.
Examples of code for this rule:
// when not configured:
import Something from "../../components/something";
// will result in
import Something from "src/components/something";
// when configured as { "prefix": "@" }
import Something from "../../components/something";
// will result in
import Something from "@/components/something";