xshell 1.3.41 → 1.3.44
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/xlint.js +22 -135
package/package.json
CHANGED
package/xlint.js
CHANGED
|
@@ -679,17 +679,18 @@ export const xlint_plugin = {
|
|
|
679
679
|
// 格式化 source, 收集 decl
|
|
680
680
|
ImportDeclaration(node) {
|
|
681
681
|
const source = node.source.value;
|
|
682
|
-
const [type, source_] = format_source(pkgs, aliases, cwd, context.filename.fp, source);
|
|
682
|
+
const [type, source_, ialias] = format_source(pkgs, aliases, cwd, context.filename.fp, source);
|
|
683
683
|
if (!source_ || source_ === source) {
|
|
684
684
|
imports.push({
|
|
685
685
|
node,
|
|
686
686
|
type,
|
|
687
|
-
style: style_fexts.has(source.fext)
|
|
687
|
+
style: style_fexts.has(source.fext),
|
|
688
|
+
ialias
|
|
688
689
|
});
|
|
689
690
|
return;
|
|
690
691
|
}
|
|
691
692
|
need_fix_source = true;
|
|
692
|
-
console.log(`自动修复 ${source} -> ${source_}`)
|
|
693
|
+
// console.log(`自动修复 ${source} -> ${source_}`)
|
|
693
694
|
context.report({
|
|
694
695
|
// @ts-ignore
|
|
695
696
|
message: `import source ${source} 应该改为 ${source_}`,
|
|
@@ -719,6 +720,8 @@ export const xlint_plugin = {
|
|
|
719
720
|
let imports_ = imports.toSorted((a, b) => {
|
|
720
721
|
if (a.style !== b.style)
|
|
721
722
|
return a.style ? -1 : 1;
|
|
723
|
+
if (a.type === 'alias' && b.type === 'alias')
|
|
724
|
+
return a.ialias - b.ialias;
|
|
722
725
|
return imtypes.indexOf(a.type) - imtypes.indexOf(b.type);
|
|
723
726
|
});
|
|
724
727
|
for (let i = 0; i < imports.length; i++) {
|
|
@@ -750,7 +753,7 @@ export const xlint_plugin = {
|
|
|
750
753
|
return text;
|
|
751
754
|
});
|
|
752
755
|
// 一次性替换所有 import
|
|
753
|
-
return fixer.replaceTextRange([_start, _end], texts.join_lines());
|
|
756
|
+
return fixer.replaceTextRange([_start, _end], texts.join_lines(false));
|
|
754
757
|
}
|
|
755
758
|
});
|
|
756
759
|
break;
|
|
@@ -759,113 +762,6 @@ export const xlint_plugin = {
|
|
|
759
762
|
};
|
|
760
763
|
}
|
|
761
764
|
}
|
|
762
|
-
// 规则太复杂了,暂时写不出来
|
|
763
|
-
// ... color ? [ ] : [
|
|
764
|
-
// '-c', 'color.status=false',
|
|
765
|
-
// '-c', 'color.ui=false',
|
|
766
|
-
// '-c', 'color.branch=false',
|
|
767
|
-
// '-c', 'color.ui=false',
|
|
768
|
-
// ],
|
|
769
|
-
// test ?
|
|
770
|
-
// ...
|
|
771
|
-
// : [ ]
|
|
772
|
-
// 'conditional-expresssion-style': {
|
|
773
|
-
// meta,
|
|
774
|
-
// create (context) {
|
|
775
|
-
// const source = context.sourceCode
|
|
776
|
-
// const lines = source.getLines()
|
|
777
|
-
// return {
|
|
778
|
-
// ConditionalExpression (node) {
|
|
779
|
-
// const question = source.getTokenAfter(node.test, not_closing_paren)
|
|
780
|
-
// const colon = source.getTokenAfter(node.consequent, not_closing_paren)
|
|
781
|
-
// const test_tail = source.getTokenBefore(question, { includeComments: true })
|
|
782
|
-
// const test_head = source.getFirstToken(node, { includeComments: true })
|
|
783
|
-
// const consequent_start = source.getTokenAfter(question, not_opening_paren)
|
|
784
|
-
// const consequent_tail = source.getTokenBefore(colon, not_closing_paren)
|
|
785
|
-
// const alternate_start = source.getTokenAfter(colon, not_opening_paren)
|
|
786
|
-
// const node_tail = source.getLastToken(node)
|
|
787
|
-
// // 三元运算符的 ? 应该和 test 条件末尾在同一行
|
|
788
|
-
// if (test_tail.loc.start.line !== question.loc.start.line)
|
|
789
|
-
// context.report({
|
|
790
|
-
// node,
|
|
791
|
-
// loc: {
|
|
792
|
-
// start: colon.loc.start,
|
|
793
|
-
// end: colon.loc.end
|
|
794
|
-
// },
|
|
795
|
-
// message: '条件表达式的 ? 应该和 test 条件末尾在同一行',
|
|
796
|
-
// fix: fixer => fixer.replaceTextRange([test_tail.range[1], colon.range[0]], ' ')
|
|
797
|
-
// })
|
|
798
|
-
// // 单行的条件表达式
|
|
799
|
-
// if (colon.loc.start.line === question.loc.start.line) {
|
|
800
|
-
// const alternate_start_with_comments = source.getTokenAfter(colon, { includeComments: true, filter: not_opening_paren })
|
|
801
|
-
// if (node_tail.loc.end.line !== colon.loc.start.line)
|
|
802
|
-
// context.report({
|
|
803
|
-
// node,
|
|
804
|
-
// loc: {
|
|
805
|
-
// start: node.alternate.loc.start,
|
|
806
|
-
// end: node_tail.loc.end
|
|
807
|
-
// },
|
|
808
|
-
// message: '单行条件表达式的 else 条件也应该在同一行',
|
|
809
|
-
// fix: fixer => fixer.replaceTextRange([colon.range[1], alternate_start_with_comments.range[0]], ' ')
|
|
810
|
-
// })
|
|
811
|
-
// } else { // 多行条件表达式
|
|
812
|
-
// if (consequent_tail.loc.end.line === colon.loc.start.line)
|
|
813
|
-
// context.report({
|
|
814
|
-
// node,
|
|
815
|
-
// loc: {
|
|
816
|
-
// start: consequent_tail.loc.start,
|
|
817
|
-
// end: colon.loc.start
|
|
818
|
-
// },
|
|
819
|
-
// message: '多行条件表达式的 : 应该在单独的一行',
|
|
820
|
-
// fix: fixer =>
|
|
821
|
-
// fixer.insertTextBefore(
|
|
822
|
-
// colon,
|
|
823
|
-
// '\n' +
|
|
824
|
-
// ' '.repeat(
|
|
825
|
-
// Math.max(split_indent(lines[consequent_tail.loc.end.line - 1]).indent - 4, 0)
|
|
826
|
-
// )
|
|
827
|
-
// )
|
|
828
|
-
// })
|
|
829
|
-
// if (
|
|
830
|
-
// alternate_start.loc.start.line === colon.loc.start.line &&
|
|
831
|
-
// (node.alternate.loc.start.line !== node.alternate.loc.end.line)
|
|
832
|
-
// )
|
|
833
|
-
// context.report({
|
|
834
|
-
// node,
|
|
835
|
-
// loc: {
|
|
836
|
-
// start: colon.loc.end,
|
|
837
|
-
// end: alternate_start.loc.start
|
|
838
|
-
// },
|
|
839
|
-
// message: '多行条件表达式的 : 应该在单独的一行',
|
|
840
|
-
// fix: fixer => fixer.insertTextBefore(
|
|
841
|
-
// alternate_start,
|
|
842
|
-
// '\n' +
|
|
843
|
-
// ' '.repeat(
|
|
844
|
-
// split_indent(lines[colon.loc.start.line - 1]).indent + 4
|
|
845
|
-
// )
|
|
846
|
-
// )
|
|
847
|
-
// })
|
|
848
|
-
// if (consequent_start.loc.start.line === question.loc.start.line)
|
|
849
|
-
// context.report({
|
|
850
|
-
// node,
|
|
851
|
-
// loc: {
|
|
852
|
-
// start: question.loc.end,
|
|
853
|
-
// end: test_head.loc.start
|
|
854
|
-
// },
|
|
855
|
-
// message: '多行条件表达式的 ? 这一行后面不应该有其他表达式,请换行',
|
|
856
|
-
// fix: fixer => fixer.insertTextBefore(
|
|
857
|
-
// consequent_start,
|
|
858
|
-
// '\n' +
|
|
859
|
-
// ' '.repeat(
|
|
860
|
-
// split_indent(lines[colon.loc.start.line - 1]).indent + 4
|
|
861
|
-
// )
|
|
862
|
-
// )
|
|
863
|
-
// })
|
|
864
|
-
// }
|
|
865
|
-
// }
|
|
866
|
-
// }
|
|
867
|
-
// }
|
|
868
|
-
// }
|
|
869
765
|
}
|
|
870
766
|
};
|
|
871
767
|
export const xlint_config = {
|
|
@@ -910,6 +806,7 @@ export const xlint_config = {
|
|
|
910
806
|
'xlint/keep-indent': 'error',
|
|
911
807
|
// 函数使用 function 来声明而不是 const foo = () => { }
|
|
912
808
|
'xlint/func-style': 'error',
|
|
809
|
+
'xlint/import': 'error',
|
|
913
810
|
'@stylistic/semi': ['error', 'never'],
|
|
914
811
|
'@stylistic/no-extra-semi': 'error',
|
|
915
812
|
'@stylistic/semi-style': ['error', 'first'],
|
|
@@ -1002,25 +899,7 @@ export const xlint_config = {
|
|
|
1002
899
|
],
|
|
1003
900
|
'@typescript-eslint/consistent-type-imports': ['error', { fixStyle: 'inline-type-imports', disallowTypeAnnotations: false }],
|
|
1004
901
|
// () => { 返回 void 的表达式 }
|
|
1005
|
-
'@typescript-eslint/no-confusing-void-expression': 'error'
|
|
1006
|
-
// ------------ import
|
|
1007
|
-
'import/no-duplicates': ['error', { 'prefer-inline': true }],
|
|
1008
|
-
'import/order': [
|
|
1009
|
-
'error',
|
|
1010
|
-
{
|
|
1011
|
-
'newlines-between': 'always-and-inside-groups',
|
|
1012
|
-
pathGroups: [
|
|
1013
|
-
{
|
|
1014
|
-
pattern: '@/**',
|
|
1015
|
-
group: 'parent'
|
|
1016
|
-
},
|
|
1017
|
-
{
|
|
1018
|
-
pattern: '@i18n/**',
|
|
1019
|
-
group: 'parent'
|
|
1020
|
-
}
|
|
1021
|
-
]
|
|
1022
|
-
}
|
|
1023
|
-
]
|
|
902
|
+
'@typescript-eslint/no-confusing-void-expression': 'error'
|
|
1024
903
|
}
|
|
1025
904
|
};
|
|
1026
905
|
const line_break_pattern = /\r\n|[\r\n\u2028\u2029]/u;
|
|
@@ -1135,7 +1014,11 @@ function get_packages(cwd) {
|
|
|
1135
1014
|
if (cache_pkgs_cwd === cwd)
|
|
1136
1015
|
return cache_pkgs;
|
|
1137
1016
|
const { dependencies = {}, devDependencies = {} } = JSON.parse(fs.readFileSync(`${cwd}package.json`, 'utf-8'));
|
|
1138
|
-
const pkgs = [
|
|
1017
|
+
const pkgs = [
|
|
1018
|
+
...Object.keys(dependencies),
|
|
1019
|
+
...Object.keys(devDependencies)
|
|
1020
|
+
.map(pkg => pkg.startsWith('@types/') ? pkg.strip_start('@types/') : pkg),
|
|
1021
|
+
].unique();
|
|
1139
1022
|
cache_pkgs_cwd = cwd;
|
|
1140
1023
|
return cache_pkgs = pkgs;
|
|
1141
1024
|
}
|
|
@@ -1181,9 +1064,10 @@ function format_source(pkgs, aliases, cwd, fp, source) {
|
|
|
1181
1064
|
source = `${source}.${resolve_suffix(source)}`;
|
|
1182
1065
|
}
|
|
1183
1066
|
const relative = source.strip_start(cwd, true);
|
|
1184
|
-
const
|
|
1185
|
-
check(
|
|
1186
|
-
|
|
1067
|
+
const ialias = aliases.findIndex(({ fp }) => relative.startsWith(fp));
|
|
1068
|
+
check(ialias !== -1, '一定能找到匹配的 alias');
|
|
1069
|
+
const alias_ = aliases[ialias];
|
|
1070
|
+
return ['alias', alias_.alias + relative.strip_start(alias_.fp), ialias];
|
|
1187
1071
|
}
|
|
1188
1072
|
let cache_exists = new Map();
|
|
1189
1073
|
function resolve_suffix(fp_base) {
|
|
@@ -1191,7 +1075,10 @@ function resolve_suffix(fp_base) {
|
|
|
1191
1075
|
const fp = `${fp_base}.${suffix}`;
|
|
1192
1076
|
const c = cache_exists.get(fp);
|
|
1193
1077
|
if (c !== undefined)
|
|
1194
|
-
|
|
1078
|
+
if (c)
|
|
1079
|
+
return suffix;
|
|
1080
|
+
else
|
|
1081
|
+
continue;
|
|
1195
1082
|
const e = fs.existsSync(fp);
|
|
1196
1083
|
cache_exists.set(fp, e);
|
|
1197
1084
|
if (e)
|