eslint-plugin-effector 0.3.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -9
- package/config/react.js +5 -0
- package/config/recommended.js +3 -0
- package/config/scope.js +5 -0
- package/index.js +8 -1
- package/package.json +13 -15
- package/rules/enforce-effect-naming-convention/enforce-effect-naming-convention.js +19 -17
- package/rules/enforce-gate-naming-convention/enforce-gate-naming-convention.js +114 -0
- package/rules/enforce-gate-naming-convention/enforce-gate-naming-convention.md +11 -0
- package/rules/enforce-store-naming-convention/enforce-store-naming-convention.js +46 -40
- package/rules/enforce-store-naming-convention/enforce-store-naming-convention.md +12 -4
- package/rules/no-ambiguity-target/no-ambiguity-target.js +8 -4
- package/rules/no-duplicate-on/no-duplicate-on.js +128 -0
- package/rules/no-duplicate-on/no-duplicate-on.md +16 -0
- package/rules/no-getState/no-getState.js +11 -36
- package/rules/no-unnecessary-combination/no-unnecessary-combination.js +96 -0
- package/rules/no-unnecessary-combination/no-unnecessary-combination.md +25 -0
- package/rules/no-unnecessary-duplication/no-unnecessary-duplication.js +9 -5
- package/rules/no-useless-methods/no-useless-methods.js +18 -4
- package/rules/no-watch/no-watch.js +53 -0
- package/rules/no-watch/no-watch.md +42 -0
- package/rules/prefer-sample-over-forward-with-mapping/prefer-sample-over-forward-with-mapping.js +8 -4
- package/rules/strict-effect-handlers/strict-effect-handlers.js +74 -0
- package/rules/strict-effect-handlers/strict-effect-handlers.md +38 -0
- package/rules/tsconfig.json +2 -1
- package/utils/create-link-to-rule.js +5 -0
- package/utils/extract-imported-from.js +9 -0
- package/utils/get-corrected-store-name.js +12 -14
- package/utils/get-nested-object-name.js +18 -0
- package/utils/get-store-name-convention.js +3 -3
- package/utils/is.js +30 -0
- package/utils/naming.js +47 -0
- package/utils/node-type-is.js +55 -0
- package/utils/validate-store-name-convention.js +7 -7
- package/.github/workflows/ci.yml +0 -43
- package/CHANGELOG.md +0 -28
- package/jest.config.js +0 -7
- package/utils/extract-imported-from-effector.js +0 -8
- package/utils/is-store-name-valid.js +0 -22
|
@@ -1,23 +1,21 @@
|
|
|
1
1
|
const { getStoreNameConvention } = require("./get-store-name-convention");
|
|
2
2
|
|
|
3
3
|
function getCorrectedStoreName(storeName, context) {
|
|
4
|
-
|
|
4
|
+
const storeNameConvention = getStoreNameConvention(context);
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return `${storeName.slice(1)}$`;
|
|
13
|
-
}
|
|
6
|
+
// handle edge case
|
|
7
|
+
if (storeName.startsWith("$") && storeName.endsWith("$")) {
|
|
8
|
+
if (storeNameConvention === "prefix") {
|
|
9
|
+
return `$${storeName.slice(0, -1)}`;
|
|
10
|
+
} else {
|
|
11
|
+
return `${storeName.slice(1)}$`;
|
|
14
12
|
}
|
|
13
|
+
}
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
: `${storeName}$`;
|
|
15
|
+
const correctedStoreName =
|
|
16
|
+
storeNameConvention === "prefix" ? `$${storeName}` : `${storeName}$`;
|
|
19
17
|
|
|
20
|
-
|
|
18
|
+
return correctedStoreName;
|
|
21
19
|
}
|
|
22
20
|
|
|
23
|
-
module.exports = { getCorrectedStoreName };
|
|
21
|
+
module.exports = { getCorrectedStoreName };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
function getNestedObjectName(node) {
|
|
2
|
+
let root = node;
|
|
3
|
+
let name = "";
|
|
4
|
+
|
|
5
|
+
while (root.type === "MemberExpression") {
|
|
6
|
+
name = `${root.property.name}.${name}`;
|
|
7
|
+
root = root.object;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (root.type === "Identifier") {
|
|
11
|
+
name = `${root.name}.${name}`;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Remove last dot
|
|
15
|
+
return name.slice(0, -1);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
module.exports = { getNestedObjectName };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
function getStoreNameConvention(context) {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
// prefix convention is default
|
|
3
|
+
return context.settings.effector?.storeNameConvention || "prefix";
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
-
module.exports = { getStoreNameConvention };
|
|
6
|
+
module.exports = { getStoreNameConvention };
|
package/utils/is.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const { nodeTypeIs } = require("./node-type-is");
|
|
2
|
+
const { namingOf } = require("./naming");
|
|
3
|
+
|
|
4
|
+
function isSomething({ isValidNaming, isTypeCorrect }) {
|
|
5
|
+
return ({ node, context }) => {
|
|
6
|
+
if (context.parserServices.hasFullTypeInformation) {
|
|
7
|
+
return isTypeCorrect({ node, context });
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return isValidNaming({ name: node?.name ?? node?.id?.name, context });
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const isStore = isSomething({
|
|
15
|
+
isTypeCorrect: nodeTypeIs.store,
|
|
16
|
+
isValidNaming: namingOf.store.isValid,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const isEffect = isSomething({
|
|
20
|
+
isTypeCorrect: nodeTypeIs.effect,
|
|
21
|
+
isValidNaming: namingOf.effect.isValid,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const is = {
|
|
25
|
+
store: (opts) => isStore(opts),
|
|
26
|
+
effect: (opts) => isEffect(opts),
|
|
27
|
+
not: { store: (opts) => !isStore(opts), effect: (opts) => !isEffect(opts) },
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
module.exports = { is };
|
package/utils/naming.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const { getStoreNameConvention } = require("./get-store-name-convention");
|
|
2
|
+
|
|
3
|
+
function isEffectNameValid({ name }) {
|
|
4
|
+
return Boolean(name?.endsWith("Fx"));
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function isGateNameValid({ name }) {
|
|
8
|
+
const [firstChar] = name.split("");
|
|
9
|
+
|
|
10
|
+
return Boolean(firstChar?.toUpperCase() === firstChar);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function isStoreNameValid({ name, context }) {
|
|
14
|
+
const storeNameConvention = getStoreNameConvention(context);
|
|
15
|
+
|
|
16
|
+
// validate edge case
|
|
17
|
+
if (name?.startsWith("$") && name?.endsWith("$")) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (storeNameConvention === "prefix" && name?.startsWith("$")) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (storeNameConvention === "postfix" && name?.endsWith("$")) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const namingOf = {
|
|
33
|
+
effect: {
|
|
34
|
+
isValid: (opts) => isEffectNameValid(opts),
|
|
35
|
+
isInvalid: (opts) => !isEffectNameValid(opts),
|
|
36
|
+
},
|
|
37
|
+
store: {
|
|
38
|
+
isValid: (opts) => isStoreNameValid(opts),
|
|
39
|
+
isInvalid: (opts) => !isStoreNameValid(opts),
|
|
40
|
+
},
|
|
41
|
+
gate: {
|
|
42
|
+
isValid: (opts) => isGateNameValid(opts),
|
|
43
|
+
isInvalid: (opts) => !isGateNameValid(opts),
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
module.exports = { namingOf };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
function hasType({ node, possibleTypes, context, from }) {
|
|
2
|
+
const checker = context.parserServices.program.getTypeChecker();
|
|
3
|
+
const originalNode = context.parserServices.esTreeNodeToTSNodeMap.get(node);
|
|
4
|
+
const type = checker.getTypeAtLocation(
|
|
5
|
+
originalNode?.initializer ?? originalNode
|
|
6
|
+
);
|
|
7
|
+
|
|
8
|
+
const symbol = type?.symbol ?? type?.aliasSymbol;
|
|
9
|
+
|
|
10
|
+
return (
|
|
11
|
+
possibleTypes.includes(symbol?.escapedName) &&
|
|
12
|
+
Boolean(symbol?.parent?.escapedName?.includes(from))
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const nodeTypeIs = {
|
|
17
|
+
effect: (opts) =>
|
|
18
|
+
hasType({ ...opts, possibleTypes: ["Effect"], from: "effector" }),
|
|
19
|
+
store: (opts) =>
|
|
20
|
+
hasType({ ...opts, possibleTypes: ["Store"], from: "effector" }),
|
|
21
|
+
event: (opts) =>
|
|
22
|
+
hasType({ ...opts, possibleTypes: ["Event"], from: "effector" }),
|
|
23
|
+
unit: (opts) =>
|
|
24
|
+
hasType({
|
|
25
|
+
...opts,
|
|
26
|
+
possibleTypes: ["Effect", "Store", "Event"],
|
|
27
|
+
from: "effector",
|
|
28
|
+
}),
|
|
29
|
+
gate: (opts) =>
|
|
30
|
+
hasType({ ...opts, possibleTypes: ["Gate"], from: "effector-react" }),
|
|
31
|
+
not: {
|
|
32
|
+
effect: (opts) =>
|
|
33
|
+
!hasType({
|
|
34
|
+
...opts,
|
|
35
|
+
possibleTypes: ["Effect"],
|
|
36
|
+
from: "effector",
|
|
37
|
+
}),
|
|
38
|
+
store: (opts) =>
|
|
39
|
+
!hasType({ ...opts, possibleTypes: ["Store"], from: "effector" }),
|
|
40
|
+
event: (opts) =>
|
|
41
|
+
!hasType({ ...opts, possibleTypes: ["Event"], from: "effector" }),
|
|
42
|
+
unit: (opts) =>
|
|
43
|
+
!hasType({
|
|
44
|
+
...opts,
|
|
45
|
+
possibleTypes: ["Effect", "Store", "Event"],
|
|
46
|
+
from: "effector",
|
|
47
|
+
}),
|
|
48
|
+
gate: (opts) =>
|
|
49
|
+
!hasType({ ...opts, possibleTypes: ["Gate"], from: "effector-react" }),
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
module.exports = {
|
|
54
|
+
nodeTypeIs,
|
|
55
|
+
};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
const { getStoreNameConvention } = require("./get-store-name-convention");
|
|
2
2
|
|
|
3
3
|
function validateStoreNameConvention(context) {
|
|
4
|
-
|
|
4
|
+
const storeNameConvention = getStoreNameConvention(context);
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
if (storeNameConvention !== "prefix" && storeNameConvention !== "postfix") {
|
|
7
|
+
throw new Error(
|
|
8
|
+
"Invalid Configuration of effector-plugin-eslint/enforce-store-naming-convention. The value should be equal to prefix or postfix."
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
module.exports = { validateStoreNameConvention };
|
|
13
|
+
module.exports = { validateStoreNameConvention };
|
package/.github/workflows/ci.yml
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
name: CI
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches: [master]
|
|
6
|
-
pull_request:
|
|
7
|
-
branches: [master]
|
|
8
|
-
|
|
9
|
-
jobs:
|
|
10
|
-
checks:
|
|
11
|
-
runs-on: ubuntu-latest
|
|
12
|
-
|
|
13
|
-
strategy:
|
|
14
|
-
matrix:
|
|
15
|
-
node-version: [14.x, 16.x]
|
|
16
|
-
|
|
17
|
-
steps:
|
|
18
|
-
- uses: actions/checkout@v2
|
|
19
|
-
- name: Use Node.js ${{ matrix.node-version }}
|
|
20
|
-
uses: actions/setup-node@v2
|
|
21
|
-
with:
|
|
22
|
-
node-version: ${{ matrix.node-version }}
|
|
23
|
-
cache: "yarn"
|
|
24
|
-
- run: yarn install
|
|
25
|
-
- run: yarn test --coverage
|
|
26
|
-
|
|
27
|
-
reports:
|
|
28
|
-
runs-on: ubuntu-latest
|
|
29
|
-
|
|
30
|
-
if: ${{ github.event_name == 'pull_request' }}
|
|
31
|
-
|
|
32
|
-
steps:
|
|
33
|
-
- uses: actions/checkout@v2
|
|
34
|
-
- name: Use Node.js
|
|
35
|
-
uses: actions/setup-node@v2
|
|
36
|
-
with:
|
|
37
|
-
cache: "yarn"
|
|
38
|
-
- run: yarn install
|
|
39
|
-
- run: yarn test --coverage
|
|
40
|
-
- name: Code Coverage Report
|
|
41
|
-
uses: romeovs/lcov-reporter-action@v0.2.11
|
|
42
|
-
with:
|
|
43
|
-
github-token: ${{ secrets.GITHUB_TOKEN }}
|
package/CHANGELOG.md
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
## v0.3.1
|
|
4
|
-
|
|
5
|
-
- Fixed false-positive in `no-ambiguity-target` with factories ([PR #50](https://github.com/effector/eslint-plugin/pull/50))
|
|
6
|
-
|
|
7
|
-
## v0.3.0
|
|
8
|
-
|
|
9
|
-
- Add new rule: `no-useless-methods` ([PR #41](https://github.com/effector/eslint-plugin/pull/41))
|
|
10
|
-
- Add new rule: `no-ambiguity-target` ([PR #42](https://github.com/effector/eslint-plugin/pull/42))
|
|
11
|
-
- Add possibility to configure store's naming convention — suffix of prefix ([PR #37](https://github.com/effector/eslint-plugin/pull/37) by @ilyaryabchinski)
|
|
12
|
-
|
|
13
|
-
## v0.2.0
|
|
14
|
-
|
|
15
|
-
- Add tests against Effector 22
|
|
16
|
-
- Specify supported Node.JS versions
|
|
17
|
-
- Add new rule: `prefer-sample-over-forward-with-mapping` ([PR #34](https://github.com/igorkamyshev/eslint-plugin-effector/pull/34))
|
|
18
|
-
|
|
19
|
-
## v0.1.4
|
|
20
|
-
|
|
21
|
-
- Exclude test-coverage report from npm-package
|
|
22
|
-
- Fixed SyntaxError in `no-unnecessary-duplication` suggestions ([PR #28](https://github.com/igorkamyshev/eslint-plugin-effector/pull/28))
|
|
23
|
-
|
|
24
|
-
## v0.1.3
|
|
25
|
-
|
|
26
|
-
- Fixed false-positive in `no-unnecessary-duplication` with composite `clock`/`source` ([PR #22](https://github.com/igorkamyshev/eslint-plugin-effector/pull/22))
|
|
27
|
-
- Fixed TypeError in `enforce-store-naming-convention` ([PR #25](https://github.com/igorkamyshev/eslint-plugin-effector/pull/25))
|
|
28
|
-
- Fixed false-positive in `enforce-effect-naming-convention` with `combine` ([PR #26](https://github.com/igorkamyshev/eslint-plugin-effector/pull/26))
|
package/jest.config.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
function extractImportedFromEffector(importedFromEffector, node) {
|
|
2
|
-
if (node.source.value === "effector") {
|
|
3
|
-
for (const s of node.specifiers) {
|
|
4
|
-
importedFromEffector.set(s.imported.name, s.local.name);
|
|
5
|
-
}
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
module.exports = { extractImportedFromEffector };
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
const { getStoreNameConvention } = require("./get-store-name-convention");
|
|
2
|
-
|
|
3
|
-
function isStoreNameValid(storeName, context) {
|
|
4
|
-
const storeNameConvention = getStoreNameConvention(context);
|
|
5
|
-
|
|
6
|
-
// validate edge case
|
|
7
|
-
if (storeName?.startsWith("$") && storeName?.endsWith("$")) {
|
|
8
|
-
return false
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
if (storeNameConvention === "prefix" && storeName?.startsWith("$")) {
|
|
12
|
-
return true;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
if (storeNameConvention === "postfix" && storeName?.endsWith("$")) {
|
|
16
|
-
return true;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
module.exports = { isStoreNameValid };
|