eslint-plugin-stratified-design 0.4.2 → 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.
|
@@ -20,14 +20,6 @@ jobs:
|
|
|
20
20
|
- name: Update package version
|
|
21
21
|
run: npm run versioning
|
|
22
22
|
|
|
23
|
-
- name: Commit and push package.json
|
|
24
|
-
run: |
|
|
25
|
-
git config --local user.email "action@github.com"
|
|
26
|
-
git config --local user.name "GitHub Action"
|
|
27
|
-
git commit -a -m "Update package version"
|
|
28
|
-
TARGET_COMMITISH=$(jq -r '.release.target_commitish' $GITHUB_EVENT_PATH)
|
|
29
|
-
git push origin HEAD:${TARGET_COMMITISH}
|
|
30
|
-
|
|
31
23
|
- name: Install dependencies
|
|
32
24
|
run: npm ci
|
|
33
25
|
|
|
@@ -2,6 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
This rule prohibits calling functions at the same level in the same file.
|
|
4
4
|
|
|
5
|
+
### Options
|
|
6
|
+
|
|
7
|
+
You can register the files to apply the rule (`no-same-level-funcs`) using the `include` and `exclude` options:
|
|
8
|
+
|
|
9
|
+
```json
|
|
10
|
+
"no-same-level-funcs": ["error", { "include": ["**/*.js"], "exclude": ["**/*.test.js"] }]
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
The default is as follows:
|
|
14
|
+
|
|
15
|
+
```json
|
|
16
|
+
{
|
|
17
|
+
"include": ["**/*.{js,ts,jsx,tsx}"],
|
|
18
|
+
"exclude": ["**/*.{spec,test}.{js,ts,jsx,tsx}"]
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
5
22
|
## Rule Details
|
|
6
23
|
|
|
7
24
|
Examples of **incorrect** code for this rule:
|
|
@@ -21,6 +38,14 @@ function func3(...) {
|
|
|
21
38
|
|
|
22
39
|
Examples of **correct** code for this rule:
|
|
23
40
|
|
|
41
|
+
```js
|
|
42
|
+
function func1(...) {
|
|
43
|
+
...
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const func2(...) => { ... }
|
|
47
|
+
```
|
|
48
|
+
|
|
24
49
|
```js
|
|
25
50
|
function func1(...) {
|
|
26
51
|
const func2(...) => { ... };
|
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
*/
|
|
5
5
|
"use strict";
|
|
6
6
|
|
|
7
|
+
const { minimatch } = require("minimatch");
|
|
8
|
+
const path = require("path");
|
|
9
|
+
|
|
7
10
|
//------------------------------------------------------------------------------
|
|
8
11
|
// Rule Definition
|
|
9
12
|
//------------------------------------------------------------------------------
|
|
@@ -13,14 +16,51 @@ module.exports = {
|
|
|
13
16
|
meta: {
|
|
14
17
|
type: "problem",
|
|
15
18
|
fixable: "code",
|
|
16
|
-
schema:
|
|
19
|
+
schema: {
|
|
20
|
+
type: "array",
|
|
21
|
+
items: [
|
|
22
|
+
{
|
|
23
|
+
type: "object",
|
|
24
|
+
properties: {
|
|
25
|
+
exclude: {
|
|
26
|
+
type: "array",
|
|
27
|
+
items: [{ type: "string" }],
|
|
28
|
+
},
|
|
29
|
+
include: {
|
|
30
|
+
type: "array",
|
|
31
|
+
items: [{ type: "string" }],
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
additionalItems: false,
|
|
37
|
+
},
|
|
17
38
|
messages: {
|
|
18
39
|
"no-same-level-funcs": "Disallow calling {{func}} in the same file.",
|
|
19
40
|
},
|
|
20
41
|
},
|
|
21
42
|
|
|
22
43
|
create(context) {
|
|
44
|
+
const options = {
|
|
45
|
+
exclude: ["**/*.{test,spec}.{js,ts,jsx,tsx}"],
|
|
46
|
+
include: ["**/*.{js,ts,jsx,tsx}"],
|
|
47
|
+
...(context.options[0] || {}),
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const fileSource = path.resolve(context.getFilename());
|
|
51
|
+
|
|
52
|
+
const isIncludedFile = options.include.find((pattern) =>
|
|
53
|
+
minimatch(fileSource, pattern)
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
const isExcludedFile =
|
|
57
|
+
!isIncludedFile ||
|
|
58
|
+
options.exclude.find((pattern) => minimatch(fileSource, pattern));
|
|
59
|
+
|
|
60
|
+
if (isExcludedFile) return {};
|
|
61
|
+
|
|
23
62
|
let funcNames;
|
|
63
|
+
|
|
24
64
|
return {
|
|
25
65
|
Program(node) {
|
|
26
66
|
funcNames = node.body.reduce((names, { type, id, declarations }) => {
|
package/package.json
CHANGED
package/scripts/versioning.js
CHANGED
|
@@ -1,16 +1,25 @@
|
|
|
1
1
|
const fs = require("fs");
|
|
2
|
+
const { execSync } = require("child_process");
|
|
3
|
+
|
|
4
|
+
const noChange = "__NO_CHANGE__";
|
|
5
|
+
|
|
6
|
+
function exec(command) {
|
|
7
|
+
const output = execSync(command, { encoding: "utf-8" });
|
|
8
|
+
console.log(output);
|
|
9
|
+
}
|
|
2
10
|
|
|
3
11
|
function updatePackageVersion() {
|
|
4
12
|
const githubEventPath = process.env.GITHUB_EVENT_PATH || "";
|
|
5
13
|
const packageJsonPath = "package.json";
|
|
6
14
|
|
|
7
|
-
const version = (() => {
|
|
15
|
+
const { version, targetCommitish } = (() => {
|
|
8
16
|
try {
|
|
9
17
|
const githubEventString = fs.readFileSync(githubEventPath, "utf-8");
|
|
10
18
|
const githubEvent = JSON.parse(githubEventString);
|
|
11
19
|
const tagName = githubEvent.release.tag_name;
|
|
20
|
+
const targetCommitish = githubEvent.release.target_commitish;
|
|
12
21
|
const version = tagName.replace(/^v(.*)/, "$1");
|
|
13
|
-
return version;
|
|
22
|
+
return { version, targetCommitish };
|
|
14
23
|
} catch (error) {
|
|
15
24
|
throw new Error("Error parsing GITHUB_EVENT_PATH:", error);
|
|
16
25
|
}
|
|
@@ -19,6 +28,7 @@ function updatePackageVersion() {
|
|
|
19
28
|
const packageJson = (() => {
|
|
20
29
|
try {
|
|
21
30
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
|
|
31
|
+
if (packageJson.version === version) return noChange;
|
|
22
32
|
packageJson.version = version;
|
|
23
33
|
const updatedPackageJson = JSON.stringify(packageJson, null, 2) + "\n";
|
|
24
34
|
return updatedPackageJson;
|
|
@@ -27,12 +37,24 @@ function updatePackageVersion() {
|
|
|
27
37
|
}
|
|
28
38
|
})();
|
|
29
39
|
|
|
40
|
+
if (packageJson === noChange) return;
|
|
41
|
+
|
|
30
42
|
try {
|
|
31
43
|
fs.writeFileSync(packageJsonPath, packageJson, "utf8");
|
|
32
|
-
console.log(`Successfully updated version to ${version}`);
|
|
33
44
|
} catch (error) {
|
|
34
45
|
throw new Error("Error writing package.json:", error);
|
|
35
46
|
}
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
exec(`git config --local user.email "action@github.com"`);
|
|
50
|
+
exec(`git config --local user.name "GitHub Action"`);
|
|
51
|
+
exec(`git commit -a -m "Update package version: ${version}"`);
|
|
52
|
+
exec(`git push origin HEAD:${targetCommitish}`);
|
|
53
|
+
} catch (error) {
|
|
54
|
+
throw new Error("Error executing push package.json", error);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
console.log(`Successfully updated version to ${version}`);
|
|
36
58
|
}
|
|
37
59
|
|
|
38
60
|
updatePackageVersion();
|
|
@@ -20,26 +20,55 @@ const ruleTester = new RuleTester({
|
|
|
20
20
|
});
|
|
21
21
|
|
|
22
22
|
ruleTester.run("no-same-level-funcs", rule, {
|
|
23
|
-
valid: [
|
|
23
|
+
valid: [
|
|
24
|
+
{
|
|
25
|
+
code: "function func1(){ function func2(){} func2() }",
|
|
26
|
+
filename: "./src/foo.js",
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
code: "function func1(){}; function func2(){ func1(); }",
|
|
30
|
+
filename: "./src/foo.test.js",
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
code: "function func1(){}; function func2(){ func1(); }",
|
|
34
|
+
filename: "./src/foo.js",
|
|
35
|
+
options: [{ exclude: ["**/foo.js"] }],
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
code: "function func1(){}; function func2(){ func1(); }",
|
|
39
|
+
filename: "./src/foo.js",
|
|
40
|
+
options: [{ include: ["**/*.ts"] }],
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
code: "function func1(){}; function func2(){ func1(); }",
|
|
44
|
+
filename: "./src/foo.js",
|
|
45
|
+
options: [{ include: ["**/src/**/*.*"], exclude: ["**/foo.js"] }],
|
|
46
|
+
},
|
|
47
|
+
],
|
|
24
48
|
invalid: [
|
|
25
49
|
{
|
|
26
50
|
code: "function func1(){}; function func2(){ func1(); }",
|
|
51
|
+
filename: "./src/foo.js",
|
|
27
52
|
errors: [{ messageId: "no-same-level-funcs", data: { func: "func1" } }],
|
|
28
53
|
},
|
|
29
54
|
{
|
|
30
55
|
code: "function func2(){ func1(); }; function func1(){}",
|
|
56
|
+
filename: "./src/foo.js",
|
|
31
57
|
errors: [{ messageId: "no-same-level-funcs", data: { func: "func1" } }],
|
|
32
58
|
},
|
|
33
59
|
{
|
|
34
60
|
code: "const func1 = () => {}; const func2 = () => { func1(); }",
|
|
61
|
+
filename: "./src/foo.js",
|
|
35
62
|
errors: [{ messageId: "no-same-level-funcs", data: { func: "func1" } }],
|
|
36
63
|
},
|
|
37
64
|
{
|
|
38
65
|
code: "const func1 = function(){}; const func2 = function(){ func1(); }",
|
|
66
|
+
filename: "./src/foo.js",
|
|
39
67
|
errors: [{ messageId: "no-same-level-funcs", data: { func: "func1" } }],
|
|
40
68
|
},
|
|
41
69
|
{
|
|
42
70
|
code: "const func1 = function func1(){}; const func2 = function func2(){ func1(); }",
|
|
71
|
+
filename: "./src/foo.js",
|
|
43
72
|
errors: [{ messageId: "no-same-level-funcs", data: { func: "func1" } }],
|
|
44
73
|
},
|
|
45
74
|
],
|