Skip to content

Commit 76f705b

Browse files
committed
merges
2 parents 5678adf + 07be509 commit 76f705b

30 files changed

+393
-110
lines changed

.circleci/config.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ jobs:
9191
- attach_workspace:
9292
at: "."
9393

94-
- run: npm i -g ts-node
9594
- run: npm run test:end-to-end
9695

9796
test-unit:
@@ -144,6 +143,10 @@ workflows:
144143
- prettier:
145144
requires:
146145
- build
146+
- test-end-to-end:
147+
requires:
148+
- build
149+
- tsc
147150
- test-unit:
148151
requires:
149152
- build

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ module.exports = {
2323
"@typescript-eslint/generic-type-naming": 0,
2424
"@typescript-eslint/indent": 0,
2525
"@typescript-eslint/member-ordering": 0,
26+
"@typescript-eslint/no-empty-function": 0,
2627
"@typescript-eslint/no-explicit-any": 0,
2728
"@typescript-eslint/no-extra-parens": 0,
2829
"@typescript-eslint/no-magic-numbers": 0,
@@ -47,7 +48,6 @@ module.exports = {
4748
"import/prefer-default-export": 0,
4849
"no-console": 0,
4950
"no-continue": 0,
50-
"no-empty-function": 0,
5151
"no-restricted-syntax": 0,
5252
"no-param-reassign": 0,
5353
"no-return-await": 0,

docs/Testing.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,5 @@ Within each directory, a test suite will execute `bin/tslint-to-eslint` and vali
4242

4343
Use `npm run test:end-to-end:accept` to overwrite the expected contents of files with what is actually written.
4444
These behave similarly to updating snapshots in snapshot testing.
45+
46+
> Note: these end-to-end tests use the compiled result of `npm run tsc`, so if you update source code, re-run `npm run tsc` before `npm run test:end-to-end`.

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,5 @@
6565
"test:end-to-end:accept": "jest --config=test/jest.config.js --globals=\"{\\\"acceptTestChanges\\\": true }\" --runInBand",
6666
"tsc": "tsc"
6767
},
68-
"version": "0.2.6"
68+
"version": "0.2.7"
6969
}

src/rules/converters.ts

Lines changed: 47 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { convertClassName } from "./converters/class-name";
1212
import { convertCurly } from "./converters/curly";
1313
import { convertCyclomaticComplexity } from "./converters/cyclomatic-complexity";
1414
import { convertEofline } from "./converters/eofline";
15-
import { convertMemberAccess } from "./converters/member-access";
15+
import { convertFileNameCasing } from "./converters/file-name-casing";
1616
import { convertForin } from "./converters/forin";
1717
import { convertFunctionConstructor } from "./converters/function-constructor";
1818
import { convertIncrementDecrement } from "./converters/increment-decrement";
@@ -24,9 +24,11 @@ import { convertLinebreakStyle } from "./converters/linebreak-style";
2424
import { convertMaxClassesPerFile } from "./converters/max-classes-per-file";
2525
import { convertMaxFileLineCount } from "./converters/max-file-line-count";
2626
import { convertMaxLineLength } from "./converters/max-line-length";
27+
import { convertMemberAccess } from "./converters/member-access";
2728
import { convertMemberOrdering } from "./converters/member-ordering";
28-
import { convertNewlinePerChainedCall } from "./converters/newline-per-chained-call";
2929
import { convertNewParens } from "./converters/new-parens";
30+
import { convertNewlineBeforeReturn } from "./converters/newline-before-return";
31+
import { convertNewlinePerChainedCall } from "./converters/newline-per-chained-call";
3032
import { convertNoAngleBracketTypeAssertion } from "./converters/no-angle-bracket-type-assertion";
3133
import { convertNoArg } from "./converters/no-arg";
3234
import { convertNoAsyncWithoutAwait } from "./converters/no-async-without-await";
@@ -39,6 +41,7 @@ import { convertNoConstantCondition } from "./converters/no-constant-condition";
3941
import { convertNoConstruct } from "./converters/no-construct";
4042
import { convertNoControlRegex } from "./converters/no-control-regex";
4143
import { convertNoDebugger } from "./converters/no-debugger";
44+
import { convertNoDuplicateImports } from "./converters/no-duplicate-imports";
4245
import { convertNoDuplicateSuper } from "./converters/no-duplicate-super";
4346
import { convertNoDuplicateSwitchCase } from "./converters/no-duplicate-switch-case";
4447
import { convertNoEmpty } from "./converters/no-empty";
@@ -95,19 +98,19 @@ import { convertPreferObjectSpread } from "./converters/prefer-object-spread";
9598
import { convertPreferReadonly } from "./converters/prefer-readonly";
9699
import { convertPreferTemplate } from "./converters/prefer-template";
97100
import { convertPromiseFunctionAsync } from "./converters/promise-function-async";
101+
import { convertQuotemark } from "./converters/quotemark";
98102
import { convertRadix } from "./converters/radix";
99103
import { convertRestrictPlusOperands } from "./converters/restrict-plus-operands";
100104
import { convertSpaceBeforeFunctionParen } from "./converters/space-before-function-paren";
101105
import { convertSwitchDefault } from "./converters/switch-default";
102-
import { convertTypedefWhitespace } from "./converters/typedef-whitespace";
106+
import { convertTripleEquals } from "./converters/triple-equals";
103107
import { convertTypeLiteralDelimiter } from "./converters/type-literal-delimiter";
108+
import { convertTypedefWhitespace } from "./converters/typedef-whitespace";
104109
import { convertTypeofCompare } from "./converters/typeof-compare";
105110
import { convertUnifiedSignatures } from "./converters/unified-signatures";
106111
import { convertUnnecessaryBind } from "./converters/unnecessary-bind";
107112
import { convertUnnecessaryConstructor } from "./converters/unnecessary-constructor";
108113
import { convertUseIsnan } from "./converters/use-isnan";
109-
import { convertQuotemark } from "./converters/quotemark";
110-
import { convertTripleEquals } from "./converters/triple-equals";
111114

112115
/**
113116
* Keys TSLint rule names to their ESLint rule converters.
@@ -116,113 +119,116 @@ export const converters = new Map([
116119
["adjacent-overload-signatures", convertAdjacentOverloadSignatures],
117120
["array-type", convertArrayType],
118121
["arrow-parens", convertArrowParens],
122+
["arrow-return-shorthand", convertArrowReturnShorthand],
119123
["await-promise", convertAwaitPromise],
120124
["ban-comma-operator", convertBanCommaOperator],
121125
["ban-ts-ignore", convertBanTsIgnore],
122126
["ban-types", convertBanTypes],
123127
["binary-expression-operand-order", convertBinaryExpressionOperandOrder],
124128
["callable-types", convertCallableTypes],
125129
["class-name", convertClassName],
130+
["curly", convertCurly],
131+
["cyclomatic-complexity", convertCyclomaticComplexity],
126132
["eofline", convertEofline],
133+
["file-name-casing", convertFileNameCasing],
127134
["forin", convertForin],
128135
["function-constructor", convertFunctionConstructor],
136+
["increment-decrement", convertIncrementDecrement],
129137
["indent", convertIndent],
130138
["interface-name", convertInterfaceName],
131139
["interface-over-type-literal", convertInterfaceOverTypeLiteral],
132140
["label-position", convertLabelPosition],
141+
["linebreak-style", convertLinebreakStyle],
142+
["max-classes-per-file", convertMaxClassesPerFile],
143+
["max-file-line-count", convertMaxFileLineCount],
144+
["max-line-length", convertMaxLineLength],
133145
["member-access", convertMemberAccess],
134146
["member-ordering", convertMemberOrdering],
135147
["new-parens", convertNewParens],
148+
["newline-before-return", convertNewlineBeforeReturn],
136149
["newline-per-chained-call", convertNewlinePerChainedCall],
137150
["no-angle-bracket-type-assertion", convertNoAngleBracketTypeAssertion],
138151
["no-any", convertNoExplicitAny],
139152
["no-arg", convertNoArg],
140153
["no-async-without-await", convertNoAsyncWithoutAwait],
154+
["no-banned-terms", convertNoBannedTerms],
141155
["no-bitwise", convertNoBitwise],
142156
["no-conditional-assignment", convertNoConditionalAssignment],
157+
["no-consecutive-blank-lines", convertNoConsecutiveBlankLines],
158+
["no-console", convertNoConsole],
159+
["no-constant-condition", convertNoConstantCondition],
143160
["no-construct", convertNoConstruct],
161+
["no-control-regex", convertNoControlRegex],
144162
["no-debugger", convertNoDebugger],
163+
["no-duplicate-imports", convertNoDuplicateImports],
145164
["no-duplicate-super", convertNoDuplicateSuper],
146165
["no-duplicate-switch-case", convertNoDuplicateSwitchCase],
147166
["no-empty-interface", convertNoEmptyInterface],
167+
["no-empty", convertNoEmpty],
148168
["no-eval", convertNoEval],
149169
["no-floating-promises", convertNoFloatingPromises],
150-
["no-for-in", convertNoForIn],
151170
["no-for-in-array", convertNoForInArray],
171+
["no-for-in", convertNoForIn],
152172
["no-inferrable-types", convertNoInferrableTypes],
153173
["no-internal-module", convertNoInternalModule],
174+
["no-invalid-regexp", convertNoInvalidRegexp],
175+
["no-invalid-template-strings", convertNoInvalidTemplateStrings],
176+
["no-invalid-this", convertNoInvalidThis],
154177
["no-irregular-whitespace", convertNoIrregularWhitespace],
178+
["no-magic-numbers", convertNoMagicNumbers],
155179
["no-misused-new", convertNoMisusedNew],
180+
["no-multiline-string", convertNoMultilineString],
156181
["no-namespace", convertNoNamespace],
157182
["no-non-null-assertion", convertNoNonNullAssertion],
158183
["no-object-literal-type-assertion", convertNoObjectLiteralTypeAssertion],
184+
["no-octal-literal", convertNoOctalLiteral],
159185
["no-parameter-properties", convertNoParameterProperties],
160186
["no-parameter-reassignment", convertNoParameterReassignment],
161187
["no-reference", convertNoReference],
188+
["no-regex-spaces", convertNoRegexSpaces],
162189
["no-require-imports", convertNoRequireImports],
163190
["no-return-await", convertNoReturnAwait],
164191
["no-sparse-arrays", convertNoSparseArrays],
165192
["no-string-literal", convertNoStringLiteral],
166193
["no-string-throw", convertNoStringThrow],
167194
["no-switch-case-fall-through", convertNoSwitchCaseFallThrough],
168-
["no-trailing-whitespace", convertNoTrailingWhitespace],
169195
["no-this-assignment", convertNoThisAssignment],
196+
["no-trailing-whitespace", convertNoTrailingWhitespace],
170197
["no-unbound-method", convertNoUnboundMethod],
171198
["no-unnecessary-class", convertNoUnnecessaryClass],
172199
["no-unnecessary-initializer", convertNoUnnecessaryInitializer],
173200
["no-unnecessary-qualifier", convertNoUnnecessaryQualifier],
201+
["no-unnecessary-semicolons", convertNoUnnecessarySemicolons],
174202
["no-unnecessary-type-assertion", convertNoUnnecessaryTypeAssertion],
175203
["no-unsafe-finally", convertNoUnsafeFinally],
176204
["no-use-before-declare", convertNoUseBeforeDeclare],
177205
["no-var-keyword", convertNoVarKeyword],
178206
["no-var-requires", convertNoVarRequires],
179207
["no-void-expression", convertNoVoidExpression],
208+
["object-literal-key-quotes", convertObjectLiteralKeyQuotes],
209+
["object-literal-shorthand", convertObjectLiteralShorthand],
210+
["one-variable-per-declaration", convertOneVariablePerDeclaration],
211+
["only-arrow-functions", convertOnlyArrowFunctions],
212+
["prefer-const", convertPreferConst],
180213
["prefer-for-of", convertPreferForOf],
214+
["prefer-function-over-method", convertPreferFunctionOverMethod],
181215
["prefer-object-spread", convertPreferObjectSpread],
216+
["prefer-readonly", convertPreferReadonly],
217+
["prefer-template", convertPreferTemplate],
182218
["promise-function-async", convertPromiseFunctionAsync],
219+
["quotemark", convertQuotemark],
183220
["radix", convertRadix],
184221
["restrict-plus-operands", convertRestrictPlusOperands],
222+
["space-before-function-paren", convertSpaceBeforeFunctionParen],
223+
["switch-default", convertSwitchDefault],
224+
["triple-equals", convertTripleEquals],
185225
["type-literal-delimiter", convertTypeLiteralDelimiter],
186226
["typedef-whitespace", convertTypedefWhitespace],
187227
["typeof-compare", convertTypeofCompare],
188228
["unified-signatures", convertUnifiedSignatures],
189229
["unnecessary-bind", convertUnnecessaryBind],
190230
["unnecessary-constructor", convertUnnecessaryConstructor],
191231
["use-isnan", convertUseIsnan],
192-
["arrow-return-shorthand", convertArrowReturnShorthand],
193-
["curly", convertCurly],
194-
["cyclomatic-complexity", convertCyclomaticComplexity],
195-
["increment-decrement", convertIncrementDecrement],
196-
["linebreak-style", convertLinebreakStyle],
197-
["max-classes-per-file", convertMaxClassesPerFile],
198-
["max-file-line-count", convertMaxFileLineCount],
199-
["max-line-length", convertMaxLineLength],
200-
["no-consecutive-blank-lines", convertNoConsecutiveBlankLines],
201-
["no-console", convertNoConsole],
202-
["no-empty", convertNoEmpty],
203-
["no-invalid-template-strings", convertNoInvalidTemplateStrings],
204-
["no-invalid-this", convertNoInvalidThis],
205-
["no-magic-numbers", convertNoMagicNumbers],
206-
["object-literal-key-quotes", convertObjectLiteralKeyQuotes],
207-
["object-literal-shorthand", convertObjectLiteralShorthand],
208-
["one-variable-per-declaration", convertOneVariablePerDeclaration],
209-
["only-arrow-functions", convertOnlyArrowFunctions],
210-
["prefer-const", convertPreferConst],
211-
["prefer-function-over-method", convertPreferFunctionOverMethod],
212-
["prefer-readonly", convertPreferReadonly],
213-
["prefer-template", convertPreferTemplate],
214-
["space-before-function-paren", convertSpaceBeforeFunctionParen],
215-
["switch-default", convertSwitchDefault],
216-
["no-banned-terms", convertNoBannedTerms],
217-
["no-constant-condition", convertNoConstantCondition],
218-
["no-control-regex", convertNoControlRegex],
219-
["no-multiline-string", convertNoMultilineString],
220-
["no-invalid-regexp", convertNoInvalidRegexp],
221-
["no-octal-literal", convertNoOctalLiteral],
222-
["no-regex-spaces", convertNoRegexSpaces],
223-
["no-unnecessary-semicolons", convertNoUnnecessarySemicolons],
224-
["quotemark", convertQuotemark],
225-
["triple-equals", convertTripleEquals],
226232

227233
// These converters are all for rules that need more complex option conversions.
228234
// Some of them will likely need to have notices about changed lint behaviors...
@@ -232,12 +238,9 @@ export const converters = new Map([
232238
// TSLint core rules:
233239
// ["ban", convertBan], // no-restricted-properties
234240
// ["import-blacklist", convertImportBlacklist], // no-restricted-imports
235-
// ["newline-before-return", convertNewlineBeforeReturn],
236241
// ["no-duplicate-variable", convertNoDuplicateVariable], // no-redeclare
237242
// ["no-shadowed-variable", convertNoShadowedVariable], // no-shadow
238-
// ["no-trailing-whitespace", convertNoTrailingWhitespace], // no-trailing-spaces
239243
// ["no-unused-expression", convertNoUnusedExpression], // no-unused-expressions
240-
// ["no-void-expression", convertNoVoidExpression], // (no exact equivalent)
241244
// ["space-within-parens", convertSpaceWithinParens], // space-in-parens
242245
// ["variable-name", convertVariableName], // a bunch of rules...
243246

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { RuleConverter } from "../converter";
2+
3+
const IGNORE_CASE_NOTICE = "ESLint (Unicorn plugin) does not support the 'ignore' case.";
4+
const CASING_BY_FILETYPE_CHANGE =
5+
"ESLint (Unicorn Plugin) does not support file name casing by file type, so all previously configured casings are now allowed.";
6+
const CASES_MAP: { [s: string]: string } = {
7+
"camel-case": "camelCase",
8+
"pascal-case": "pascalCase",
9+
"kebab-case": "kebabCase",
10+
"snake-case": "snakeCase",
11+
};
12+
13+
export const convertFileNameCasing: RuleConverter = tslintRule => {
14+
return {
15+
rules: [
16+
{
17+
ruleName: "unicorn/filename-case",
18+
...collectArguments(tslintRule.ruleArguments),
19+
},
20+
],
21+
plugins: ["unicorn"],
22+
};
23+
};
24+
25+
const collectArguments = (ruleArguments: any[]) => {
26+
const notices: string[] = [];
27+
const foundCases: { [k: string]: boolean } = {};
28+
29+
if (ruleArguments.length === 0 || ruleArguments[0] === false || ruleArguments.length < 2) {
30+
return undefined;
31+
}
32+
33+
const casings = ruleArguments[1];
34+
if (typeof casings === "string") {
35+
if (casings === "ignore") {
36+
notices.push(IGNORE_CASE_NOTICE);
37+
} else {
38+
foundCases[CASES_MAP[casings]] = true;
39+
}
40+
}
41+
42+
if (ruleArguments[1] instanceof Object) {
43+
notices.push(CASING_BY_FILETYPE_CHANGE);
44+
for (const casing in casings) {
45+
if (casings[casing] === "ignore") {
46+
notices.push(IGNORE_CASE_NOTICE);
47+
} else {
48+
foundCases[CASES_MAP[casings[casing]]] = true;
49+
}
50+
}
51+
}
52+
53+
return {
54+
...(notices.length > 0 && { notices }),
55+
ruleArguments: [
56+
{
57+
cases: foundCases,
58+
},
59+
],
60+
};
61+
};

src/rules/converters/max-line-length.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@ export const convertMaxLineLength: RuleConverter = tslintRule => {
1212
};
1313

1414
const collectArguments = (ruleArguments: any[]) => {
15-
if (ruleArguments.length === 0 || ruleArguments[0] === false || ruleArguments.length < 2) {
15+
if (ruleArguments.length === 0) {
1616
return undefined;
1717
}
1818

19-
if (ruleArguments.length === 2 && typeof ruleArguments[1] === "number") {
19+
const argument = ruleArguments[0];
20+
21+
if (typeof argument === "number") {
2022
return {
2123
ruleArguments: [
2224
{
23-
code: ruleArguments[1],
25+
code: argument,
2426
},
2527
],
2628
};
2729
}
2830

29-
const argument = ruleArguments[1];
30-
3131
return {
3232
ruleArguments: [
3333
{
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { RuleConverter } from "../converter";
2+
3+
export const convertNewlineBeforeReturn: RuleConverter = () => {
4+
return {
5+
rules: [
6+
{
7+
ruleName: "padding-line-between-statements",
8+
ruleArguments: [
9+
"error",
10+
{
11+
blankLine: "always",
12+
prev: "*",
13+
next: "return",
14+
},
15+
],
16+
},
17+
],
18+
};
19+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { RuleConverter } from "../converter";
2+
3+
export const convertNoDuplicateImports: RuleConverter = tslintRule => {
4+
return {
5+
rules: [
6+
{
7+
...(tslintRule.ruleArguments.includes("allow-namespace-imports") && {
8+
notices: ["ESLint does not support optional config allow-namespace-imports."],
9+
}),
10+
ruleName: "no-duplicate-imports",
11+
},
12+
],
13+
};
14+
};

0 commit comments

Comments
 (0)