@simplysm/eslint-plugin 12.15.39 → 12.15.41
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/package.json +1 -1
- package/src/configs/root.js +4 -1
- package/src/plugin.js +2 -0
- package/src/rules/no-hard-private.js +66 -0
package/package.json
CHANGED
package/src/configs/root.js
CHANGED
|
@@ -64,8 +64,9 @@ export default [
|
|
|
64
64
|
},
|
|
65
65
|
],
|
|
66
66
|
|
|
67
|
-
|
|
67
|
+
//-- 심플리즘
|
|
68
68
|
"@simplysm/no-subpath-imports-from-simplysm": ["error"],
|
|
69
|
+
"@simplysm/no-hard-private": ["error"],
|
|
69
70
|
},
|
|
70
71
|
},
|
|
71
72
|
{
|
|
@@ -134,6 +135,7 @@ export default [
|
|
|
134
135
|
},
|
|
135
136
|
],
|
|
136
137
|
"@typescript-eslint/prefer-ts-expect-error": ["error"],
|
|
138
|
+
"@typescript-eslint/prefer-readonly": ["error"],
|
|
137
139
|
/*"@typescript-eslint/explicit-member-accessibility": [
|
|
138
140
|
"error",
|
|
139
141
|
{
|
|
@@ -203,6 +205,7 @@ export default [
|
|
|
203
205
|
//-- 심플리즘
|
|
204
206
|
"@simplysm/ts-no-throw-not-implement-error": ["warn"],
|
|
205
207
|
"@simplysm/no-subpath-imports-from-simplysm": ["error"],
|
|
208
|
+
"@simplysm/no-hard-private": ["error"],
|
|
206
209
|
|
|
207
210
|
// -- 아래 적용 검토가 필요한것
|
|
208
211
|
"import/no-extraneous-dependencies": [
|
package/src/plugin.js
CHANGED
|
@@ -4,6 +4,7 @@ import tsNoExportedTypes from "./rules/ts-no-exported-types.js";
|
|
|
4
4
|
import tsNoBufferInTypedArrayContext from "./rules/ts-no-buffer-in-typedarray-context.js";
|
|
5
5
|
import noSubpathImportsFromSimplysm from "./rules/no-subpath-imports-from-simplysm.js";
|
|
6
6
|
import ngTemplateSdRequireBindingAttrs from "./rules/ng-template-sd-require-binding-attrs.js";
|
|
7
|
+
import noHardPrivate from "./rules/no-hard-private.js";
|
|
7
8
|
|
|
8
9
|
export default {
|
|
9
10
|
rules: {
|
|
@@ -13,5 +14,6 @@ export default {
|
|
|
13
14
|
"ng-template-no-todo-comments": ngTemplateNoTodoComments,
|
|
14
15
|
"no-subpath-imports-from-simplysm": noSubpathImportsFromSimplysm,
|
|
15
16
|
"ng-template-sd-require-binding-attrs": ngTemplateSdRequireBindingAttrs,
|
|
17
|
+
"no-hard-private": noHardPrivate,
|
|
16
18
|
},
|
|
17
19
|
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
meta: {
|
|
3
|
+
type: "problem",
|
|
4
|
+
docs: {
|
|
5
|
+
description: 'Enforce TypeScript "private _" style over ECMAScript "#" private fields.',
|
|
6
|
+
},
|
|
7
|
+
messages: {
|
|
8
|
+
preferSoftPrivate: 'Hard private fields (#) are not allowed. Use "private _" instead.',
|
|
9
|
+
},
|
|
10
|
+
fixable: "code",
|
|
11
|
+
schema: [],
|
|
12
|
+
},
|
|
13
|
+
create(context) {
|
|
14
|
+
const sourceCode = context.sourceCode; // 소스 코드 접근 객체
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
// 1. 선언부 감지
|
|
18
|
+
"PropertyDefinition > PrivateIdentifier, MethodDefinition > PrivateIdentifier"(node) {
|
|
19
|
+
const parent = node.parent;
|
|
20
|
+
const identifierName = node.name; // '#'을 제외한 이름
|
|
21
|
+
|
|
22
|
+
context.report({
|
|
23
|
+
node: node,
|
|
24
|
+
messageId: "preferSoftPrivate",
|
|
25
|
+
fix(fixer) {
|
|
26
|
+
const fixes = [];
|
|
27
|
+
|
|
28
|
+
// 1-1. 이름 변경 (#a -> _a)
|
|
29
|
+
fixes.push(fixer.replaceText(node, `_${identifierName}`));
|
|
30
|
+
|
|
31
|
+
// 1-2. 'private' 접근 제어자 추가 위치 계산
|
|
32
|
+
if (!parent.accessibility) {
|
|
33
|
+
// 기본 삽입 위치: 부모 노드의 시작 지점 (static, async 등 포함)
|
|
34
|
+
let tokenToInsertBefore = sourceCode.getFirstToken(parent);
|
|
35
|
+
|
|
36
|
+
// 데코레이터가 있다면, 마지막 데코레이터 '다음' 토큰 앞에 삽입
|
|
37
|
+
// (@Deco private static _foo)
|
|
38
|
+
if (parent.decorators && parent.decorators.length > 0) {
|
|
39
|
+
const lastDecorator = parent.decorators[parent.decorators.length - 1];
|
|
40
|
+
tokenToInsertBefore = sourceCode.getTokenAfter(lastDecorator);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// tokenToInsertBefore는 이제 'static', 'async', 'readonly' 또는 변수명('_foo')입니다.
|
|
44
|
+
// 이 앞에 'private '를 붙이면 자연스럽게 'private static ...' 순서가 됩니다.
|
|
45
|
+
fixes.push(fixer.insertTextBefore(tokenToInsertBefore, "private "));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return fixes;
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
// 2. 사용부 감지 (this.#field) - 변경 없음
|
|
54
|
+
"MemberExpression > PrivateIdentifier"(node) {
|
|
55
|
+
const identifierName = node.name;
|
|
56
|
+
context.report({
|
|
57
|
+
node: node,
|
|
58
|
+
messageId: "preferSoftPrivate",
|
|
59
|
+
fix(fixer) {
|
|
60
|
+
return fixer.replaceText(node, `_${identifierName}`);
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
};
|