@harness-engineering/eslint-plugin 0.2.0 → 0.2.2
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 +8 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +63 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -89,6 +89,14 @@ Create `harness.config.json` in your project root:
|
|
|
89
89
|
| `no-sync-io-in-async` | Disallow synchronous I/O in async functions | warn |
|
|
90
90
|
| `no-unbounded-array-chains` | Disallow unbounded array method chains | warn |
|
|
91
91
|
|
|
92
|
+
### Cross-Platform Rules
|
|
93
|
+
|
|
94
|
+
| Rule | Description | Default |
|
|
95
|
+
| ----------------------------- | --------------------------------------------- | ------- |
|
|
96
|
+
| `no-unix-shell-command` | Disallow Unix-specific shell commands | warn |
|
|
97
|
+
| `no-hardcoded-path-separator` | Disallow hardcoded path separators | warn |
|
|
98
|
+
| `require-path-normalization` | Require path normalization for cross-platform | warn |
|
|
99
|
+
|
|
92
100
|
## Configs
|
|
93
101
|
|
|
94
102
|
- **recommended**: Architecture rules as errors, others as warnings
|
package/dist/index.d.ts
CHANGED
|
@@ -34,6 +34,9 @@ declare const rules: {
|
|
|
34
34
|
'require-boundary-schema': _typescript_eslint_utils_ts_eslint.RuleModule<"missingSchema", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
35
35
|
name: string;
|
|
36
36
|
};
|
|
37
|
+
'require-path-normalization': _typescript_eslint_utils_ts_eslint.RuleModule<"missingNormalization", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
38
|
+
name: string;
|
|
39
|
+
};
|
|
37
40
|
};
|
|
38
41
|
|
|
39
42
|
declare const plugin: {
|
|
@@ -75,6 +78,9 @@ declare const plugin: {
|
|
|
75
78
|
'require-boundary-schema': _typescript_eslint_utils_ts_eslint.RuleModule<"missingSchema", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
76
79
|
name: string;
|
|
77
80
|
};
|
|
81
|
+
'require-path-normalization': _typescript_eslint_utils_ts_eslint.RuleModule<"missingNormalization", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
82
|
+
name: string;
|
|
83
|
+
};
|
|
78
84
|
};
|
|
79
85
|
configs: {
|
|
80
86
|
recommended: {
|
|
@@ -89,6 +95,7 @@ declare const plugin: {
|
|
|
89
95
|
'@harness-engineering/enforce-doc-exports': string;
|
|
90
96
|
'@harness-engineering/no-unix-shell-command': string;
|
|
91
97
|
'@harness-engineering/no-hardcoded-path-separator': string;
|
|
98
|
+
'@harness-engineering/require-path-normalization': string;
|
|
92
99
|
};
|
|
93
100
|
};
|
|
94
101
|
strict: {
|
|
@@ -103,6 +110,7 @@ declare const plugin: {
|
|
|
103
110
|
'@harness-engineering/enforce-doc-exports': string;
|
|
104
111
|
'@harness-engineering/no-unix-shell-command': string;
|
|
105
112
|
'@harness-engineering/no-hardcoded-path-separator': string;
|
|
113
|
+
'@harness-engineering/require-path-normalization': string;
|
|
106
114
|
};
|
|
107
115
|
};
|
|
108
116
|
};
|
|
@@ -150,6 +158,9 @@ declare const configs: {
|
|
|
150
158
|
'require-boundary-schema': _typescript_eslint_utils_ts_eslint.RuleModule<"missingSchema", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
151
159
|
name: string;
|
|
152
160
|
};
|
|
161
|
+
'require-path-normalization': _typescript_eslint_utils_ts_eslint.RuleModule<"missingNormalization", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
162
|
+
name: string;
|
|
163
|
+
};
|
|
153
164
|
};
|
|
154
165
|
configs: /*elided*/ any;
|
|
155
166
|
};
|
|
@@ -162,6 +173,7 @@ declare const configs: {
|
|
|
162
173
|
'@harness-engineering/enforce-doc-exports': string;
|
|
163
174
|
'@harness-engineering/no-unix-shell-command': string;
|
|
164
175
|
'@harness-engineering/no-hardcoded-path-separator': string;
|
|
176
|
+
'@harness-engineering/require-path-normalization': string;
|
|
165
177
|
};
|
|
166
178
|
};
|
|
167
179
|
strict: {
|
|
@@ -205,6 +217,9 @@ declare const configs: {
|
|
|
205
217
|
'require-boundary-schema': _typescript_eslint_utils_ts_eslint.RuleModule<"missingSchema", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
206
218
|
name: string;
|
|
207
219
|
};
|
|
220
|
+
'require-path-normalization': _typescript_eslint_utils_ts_eslint.RuleModule<"missingNormalization", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
221
|
+
name: string;
|
|
222
|
+
};
|
|
208
223
|
};
|
|
209
224
|
configs: /*elided*/ any;
|
|
210
225
|
};
|
|
@@ -217,6 +232,7 @@ declare const configs: {
|
|
|
217
232
|
'@harness-engineering/enforce-doc-exports': string;
|
|
218
233
|
'@harness-engineering/no-unix-shell-command': string;
|
|
219
234
|
'@harness-engineering/no-hardcoded-path-separator': string;
|
|
235
|
+
'@harness-engineering/require-path-normalization': string;
|
|
220
236
|
};
|
|
221
237
|
};
|
|
222
238
|
};
|
package/dist/index.js
CHANGED
|
@@ -867,6 +867,63 @@ var no_hardcoded_path_separator_default = createRule10({
|
|
|
867
867
|
}
|
|
868
868
|
});
|
|
869
869
|
|
|
870
|
+
// src/rules/require-path-normalization.ts
|
|
871
|
+
import { ESLintUtils as ESLintUtils11 } from "@typescript-eslint/utils";
|
|
872
|
+
var createRule11 = ESLintUtils11.RuleCreator(
|
|
873
|
+
(name) => `https://github.com/harness-engineering/eslint-plugin/blob/main/docs/rules/${name}.md`
|
|
874
|
+
);
|
|
875
|
+
function isRelativeCall(node) {
|
|
876
|
+
const callee = node.callee;
|
|
877
|
+
if (callee.type === "Identifier" && callee.name === "relative") {
|
|
878
|
+
return true;
|
|
879
|
+
}
|
|
880
|
+
if (callee.type === "MemberExpression" && callee.object.type === "Identifier" && callee.object.name === "path" && callee.property.type === "Identifier" && callee.property.name === "relative") {
|
|
881
|
+
return true;
|
|
882
|
+
}
|
|
883
|
+
return false;
|
|
884
|
+
}
|
|
885
|
+
function isReplaceMethod(parent) {
|
|
886
|
+
return parent.type === "MemberExpression" && parent.property.type === "Identifier" && (parent.property.name === "replaceAll" || parent.property.name === "replace");
|
|
887
|
+
}
|
|
888
|
+
function isBackslashNormalizationArg(firstArg) {
|
|
889
|
+
if (firstArg.type === "Literal" && firstArg.value === "\\") return true;
|
|
890
|
+
if ("regex" in firstArg && firstArg.type === "Literal") return true;
|
|
891
|
+
return false;
|
|
892
|
+
}
|
|
893
|
+
function hasNormalization(node) {
|
|
894
|
+
const parent = node.parent;
|
|
895
|
+
if (!parent || !isReplaceMethod(parent)) return false;
|
|
896
|
+
const grandparent = parent.parent;
|
|
897
|
+
if (grandparent?.type !== "CallExpression" || grandparent.arguments.length < 1) return false;
|
|
898
|
+
return isBackslashNormalizationArg(grandparent.arguments[0]);
|
|
899
|
+
}
|
|
900
|
+
var require_path_normalization_default = createRule11({
|
|
901
|
+
name: "require-path-normalization",
|
|
902
|
+
meta: {
|
|
903
|
+
type: "problem",
|
|
904
|
+
docs: {
|
|
905
|
+
description: 'Require path.relative() results to be normalized with .replaceAll("\\\\", "/") for cross-platform safety'
|
|
906
|
+
},
|
|
907
|
+
messages: {
|
|
908
|
+
missingNormalization: "path.relative() result must be normalized with .replaceAll('\\\\', '/') for cross-platform compatibility."
|
|
909
|
+
},
|
|
910
|
+
schema: []
|
|
911
|
+
},
|
|
912
|
+
defaultOptions: [],
|
|
913
|
+
create(context) {
|
|
914
|
+
return {
|
|
915
|
+
CallExpression(node) {
|
|
916
|
+
if (!isRelativeCall(node)) return;
|
|
917
|
+
if (hasNormalization(node)) return;
|
|
918
|
+
context.report({
|
|
919
|
+
node,
|
|
920
|
+
messageId: "missingNormalization"
|
|
921
|
+
});
|
|
922
|
+
}
|
|
923
|
+
};
|
|
924
|
+
}
|
|
925
|
+
});
|
|
926
|
+
|
|
870
927
|
// src/rules/index.ts
|
|
871
928
|
var rules = {
|
|
872
929
|
"enforce-doc-exports": enforce_doc_exports_default,
|
|
@@ -878,7 +935,8 @@ var rules = {
|
|
|
878
935
|
"no-sync-io-in-async": no_sync_io_in_async_default,
|
|
879
936
|
"no-unbounded-array-chains": no_unbounded_array_chains_default,
|
|
880
937
|
"no-unix-shell-command": no_unix_shell_command_default,
|
|
881
|
-
"require-boundary-schema": require_boundary_schema_default
|
|
938
|
+
"require-boundary-schema": require_boundary_schema_default,
|
|
939
|
+
"require-path-normalization": require_path_normalization_default
|
|
882
940
|
};
|
|
883
941
|
|
|
884
942
|
// src/index.ts
|
|
@@ -902,7 +960,8 @@ var plugin = {
|
|
|
902
960
|
"@harness-engineering/require-boundary-schema": "warn",
|
|
903
961
|
"@harness-engineering/enforce-doc-exports": "warn",
|
|
904
962
|
"@harness-engineering/no-unix-shell-command": "warn",
|
|
905
|
-
"@harness-engineering/no-hardcoded-path-separator": "warn"
|
|
963
|
+
"@harness-engineering/no-hardcoded-path-separator": "warn",
|
|
964
|
+
"@harness-engineering/require-path-normalization": "warn"
|
|
906
965
|
}
|
|
907
966
|
},
|
|
908
967
|
strict: {
|
|
@@ -918,7 +977,8 @@ var plugin = {
|
|
|
918
977
|
"@harness-engineering/require-boundary-schema": "error",
|
|
919
978
|
"@harness-engineering/enforce-doc-exports": "error",
|
|
920
979
|
"@harness-engineering/no-unix-shell-command": "error",
|
|
921
|
-
"@harness-engineering/no-hardcoded-path-separator": "error"
|
|
980
|
+
"@harness-engineering/no-hardcoded-path-separator": "error",
|
|
981
|
+
"@harness-engineering/require-path-normalization": "error"
|
|
922
982
|
}
|
|
923
983
|
}
|
|
924
984
|
}
|