0.0.6 ā¢ Published 2 years ago
@takurinton/eslint-plugin-limit-import-scope v0.0.6
eslint-plugin-limit-import-scope
What
Plugin to follow code conventions for fluct_ms.
Don't allow importing modules from patterns other than the specified one.
Install
npm
npm i --save-dev @takurinton/eslint-plugin-limit-import-scope
yarn
yarn add -D @takurinton/eslint-plugin-limit-import-scope
Usage
The hierarchy below you is allowed to import by default.
In .eslintrc.js
"plugins": [
"@takurinton/limit-import-scope",
],
"rules": {
"@takurinton/limit-import-scope/": [
"error", {
patterns: ["utils/", "atoms", "actions"], // allow in patterns
},
],
}
Example
Specify the paths you want to allow in patterns.
// app/.eslintrc.js
"plugins": [
"@takurinton/limit-import-scope",
],
"rules": {
"@takurinton/limit-import-scope/": [
"error", {
patterns: ["utils/", "atoms", "actions"], // allow patterns
},
],
}
Patterns and the modules contained in node_modules that are allowed are allowed.
Not allowed ../Piyo/internal/useForm
is an error.
// app/src/Home/index.tsx
import React from "react"; // good
import { useForm } from "../Piyo/internal/useForm"; // bad
import { Component } from "./internal/Components"; // good
import { hoge } from "../../../utils/hoge"; // good
import * as Styled from "./styled"; // good
export const Home = () => {
return (
<div>
<p>hello world</p>
<Component />
</div>
);
};
run eslint
$ eslint 'src/playground/**/*.{ts,tsx}'
app/src/Home/index.tsx
2:1 error Don't allow import '../Piyo/internal/useForm' limit-import-scope
ā 1 problem (1 error, 0 warnings)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.