@dextinity/eslint-plugin 2.0.0-canary-20260729062014
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/LICENSE +24 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.js +14 -0
- package/lib/rules/no-other-module-relative-import.d.ts +3 -0
- package/lib/rules/no-other-module-relative-import.js +66 -0
- package/lib/rules/no-private-sibling-import.d.ts +3 -0
- package/lib/rules/no-private-sibling-import.js +63 -0
- package/package.json +56 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
BSD 2-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023, Vivid Planet Software GmbH
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
|
7
|
+
|
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
+
list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
|
13
|
+
and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
16
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
17
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
18
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
19
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
20
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
21
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
22
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
23
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
24
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var no_other_module_relative_import_1 = __importDefault(require("./rules/no-other-module-relative-import"));
|
|
7
|
+
var no_private_sibling_import_1 = __importDefault(require("./rules/no-private-sibling-import"));
|
|
8
|
+
var plugin = {
|
|
9
|
+
rules: {
|
|
10
|
+
"no-private-sibling-import": no_private_sibling_import_1.default,
|
|
11
|
+
"no-other-module-relative-import": no_other_module_relative_import_1.default,
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
module.exports = plugin;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var path_1 = __importDefault(require("path"));
|
|
7
|
+
function parentDirCount(dir) {
|
|
8
|
+
var match = dir.match(/^(\.\.\/)*/);
|
|
9
|
+
return match[0].length / 3;
|
|
10
|
+
}
|
|
11
|
+
exports.default = {
|
|
12
|
+
meta: {
|
|
13
|
+
type: "suggestion",
|
|
14
|
+
fixable: "code",
|
|
15
|
+
schema: [
|
|
16
|
+
{
|
|
17
|
+
type: "object",
|
|
18
|
+
properties: {
|
|
19
|
+
sourceRoot: {
|
|
20
|
+
type: "string",
|
|
21
|
+
},
|
|
22
|
+
sourceRootAlias: {
|
|
23
|
+
type: "string",
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
additionalProperties: false,
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
create: function (context) {
|
|
31
|
+
return {
|
|
32
|
+
ImportDeclaration: function (node) {
|
|
33
|
+
var _a;
|
|
34
|
+
var options = (_a = context.options[0]) !== null && _a !== void 0 ? _a : { sourceRoot: "./src", sourceRootAlias: "@src" };
|
|
35
|
+
var importParentDirCount = parentDirCount(node.source.value.toString());
|
|
36
|
+
if (!importParentDirCount) {
|
|
37
|
+
// import is not relative
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
var filePath = context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename();
|
|
41
|
+
if (filePath == "<text>")
|
|
42
|
+
return; // If the input is from stdin, this test can't fail
|
|
43
|
+
var sourceDir = "".concat(context.getCwd(), "/").concat(options.sourceRoot);
|
|
44
|
+
var fileDir = path_1.default.dirname(filePath);
|
|
45
|
+
var relativeFileToSourceDir = path_1.default.relative(sourceDir, fileDir);
|
|
46
|
+
if (!relativeFileToSourceDir || relativeFileToSourceDir.startsWith("..")) {
|
|
47
|
+
// file is not in source directory
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
var fileSubdirectoriesCount = relativeFileToSourceDir.split(path_1.default.sep).length;
|
|
51
|
+
// importParentDirCount is the number of ../ parts in the import path
|
|
52
|
+
// fileSubdirectoriesCount is the number of subdirectories in the file path relative to the source directory
|
|
53
|
+
if (importParentDirCount >= fileSubdirectoriesCount) {
|
|
54
|
+
context.report({
|
|
55
|
+
node: node,
|
|
56
|
+
message: "Avoid relative import from other module",
|
|
57
|
+
fix: function (fixer) {
|
|
58
|
+
var importPathRelativeToSourceDir = path_1.default.relative(sourceDir, "".concat(fileDir, "/").concat(node.source.value.toString()));
|
|
59
|
+
return fixer.replaceText(node.source, "\"".concat(options.sourceRootAlias, "/").concat(importPathRelativeToSourceDir, "\""));
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var path_1 = __importDefault(require("path"));
|
|
7
|
+
exports.default = {
|
|
8
|
+
meta: {
|
|
9
|
+
type: "suggestion",
|
|
10
|
+
schema: [
|
|
11
|
+
{
|
|
12
|
+
type: "array",
|
|
13
|
+
description: "List of private sibling file extensions, defaults to gql, sc",
|
|
14
|
+
items: {
|
|
15
|
+
type: "string",
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
},
|
|
20
|
+
create: function (context) {
|
|
21
|
+
return {
|
|
22
|
+
ImportDeclaration: function (node) {
|
|
23
|
+
var _a;
|
|
24
|
+
var optionSiblingExtensions = (_a = context.options[0]) !== null && _a !== void 0 ? _a : ["gql", "sc"];
|
|
25
|
+
var filePath = context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename();
|
|
26
|
+
if (filePath == "<text>")
|
|
27
|
+
return; // If the input is from stdin, this test can't fail
|
|
28
|
+
var isPrivateFileMatch = String(node.source.value).match(new RegExp("^(.*)\\.(".concat(optionSiblingExtensions.join("|"), ")$")));
|
|
29
|
+
if (isPrivateFileMatch) {
|
|
30
|
+
if (!isPrivateFileMatch[1].startsWith("./")) {
|
|
31
|
+
context.report({
|
|
32
|
+
node: node,
|
|
33
|
+
message: "Import private siblings always with relative imports",
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
var baseName = path_1.default.basename(filePath);
|
|
38
|
+
if (baseName.endsWith(".tsx")) {
|
|
39
|
+
baseName = baseName.slice(0, -4);
|
|
40
|
+
}
|
|
41
|
+
else if (baseName.endsWith(".ts")) {
|
|
42
|
+
baseName = baseName.slice(0, -3);
|
|
43
|
+
}
|
|
44
|
+
for (var _i = 0, optionSiblingExtensions_1 = optionSiblingExtensions; _i < optionSiblingExtensions_1.length; _i++) {
|
|
45
|
+
var ext = optionSiblingExtensions_1[_i];
|
|
46
|
+
var suffix = ".".concat(ext);
|
|
47
|
+
if (baseName.endsWith(suffix)) {
|
|
48
|
+
baseName = baseName.slice(0, -suffix.length);
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (isPrivateFileMatch[1] != "./".concat(baseName)) {
|
|
53
|
+
context.report({
|
|
54
|
+
node: node,
|
|
55
|
+
message: "Avoid private sibling import from other files",
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
},
|
|
63
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dextinity/eslint-plugin",
|
|
3
|
+
"version": "2.0.0-canary-20260729062014",
|
|
4
|
+
"description": "A set of ESLint rules and configurations for Comet projects",
|
|
5
|
+
"type": "commonjs",
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"license": "BSD-2-Clause",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"files": [
|
|
10
|
+
"lib"
|
|
11
|
+
],
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"@eslint/js": "^9.39.4",
|
|
14
|
+
"eslint": "^9.39.4",
|
|
15
|
+
"eslint-config-prettier": "^10.1.8",
|
|
16
|
+
"eslint-plugin-import": "^2.32.0",
|
|
17
|
+
"eslint-plugin-jsonc": "^2.21.1",
|
|
18
|
+
"eslint-plugin-package-json": "^0.91.2",
|
|
19
|
+
"eslint-plugin-prettier": "^5.5.6",
|
|
20
|
+
"eslint-plugin-simple-import-sort": "^12.1.1",
|
|
21
|
+
"eslint-plugin-unused-imports": "^4.4.1",
|
|
22
|
+
"globals": "^15.15.0",
|
|
23
|
+
"npm-run-all2": "^8.0.4",
|
|
24
|
+
"prettier": "^3.6.2",
|
|
25
|
+
"typescript": "^5.9.3",
|
|
26
|
+
"typescript-eslint": "^8.62.1",
|
|
27
|
+
"vitest": "^4.1.8"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"eslint": ">=9",
|
|
31
|
+
"prettier": ">=3"
|
|
32
|
+
},
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=22.0.0"
|
|
35
|
+
},
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public",
|
|
38
|
+
"registry": "https://registry.npmjs.org"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "pnpm run clean && tsc --project ./tsconfig.build.json",
|
|
42
|
+
"clean": "rimraf lib",
|
|
43
|
+
"dev": "tsc --watch",
|
|
44
|
+
"lint": "run-p lint:prettier lint:eslint lint:tsc",
|
|
45
|
+
"lint:ci": "pnpm run lint",
|
|
46
|
+
"lint:eslint": "eslint --max-warnings 0 src/ '**/*.json' --no-warn-ignored",
|
|
47
|
+
"lint:fix": "run-p lint:fix:eslint lint:fix:prettier",
|
|
48
|
+
"lint:fix:eslint": "pnpm run lint:eslint --fix",
|
|
49
|
+
"lint:fix:prettier": "pnpm run lint:prettier --write",
|
|
50
|
+
"lint:prettier": "pnpm exec prettier --check '*.{ts,js,json,md,yml,yaml}'",
|
|
51
|
+
"lint:tsc": "tsc --noEmit",
|
|
52
|
+
"test": "pnpm run test:unit",
|
|
53
|
+
"test:unit": "vitest --run",
|
|
54
|
+
"test:watch": "vitest --watch"
|
|
55
|
+
}
|
|
56
|
+
}
|