diff --git a/cmd/rslint/api.go b/cmd/rslint/api.go index e868c7e9..628d0b1b 100644 --- a/cmd/rslint/api.go +++ b/cmd/rslint/api.go @@ -3,6 +3,7 @@ package main import ( "fmt" "os" + "sort" "sync" "github.com/microsoft/typescript-go/shim/ast" @@ -219,6 +220,16 @@ func (h *IPCHandler) HandleLint(req api.LintRequest) (*api.LintResponse, error) if diagnostics == nil { diagnostics = []api.Diagnostic{} } + // sort diagnostics + sort.Slice(diagnostics, func(i, j int) bool { + if diagnostics[i].FilePath != diagnostics[j].FilePath { + return diagnostics[i].FilePath < diagnostics[j].FilePath + } + if diagnostics[i].Range.Start.Line != diagnostics[j].Range.Start.Line { + return diagnostics[i].Range.Start.Line < diagnostics[j].Range.Start.Line + } + return diagnostics[i].Range.Start.Column < diagnostics[j].Range.Start.Column + }) // Create response response := &api.LintResponse{ diff --git a/internal/rules/dot_notation/dot_notation.go b/internal/rules/dot_notation/dot_notation.go index 07bc85c2..c23a055a 100644 --- a/internal/rules/dot_notation/dot_notation.go +++ b/internal/rules/dot_notation/dot_notation.go @@ -371,7 +371,7 @@ var DotNotationRule = rule.CreateRule(rule.Rule{ replacement := objectText + whitespace + "." + propName // Report on the node with the fix - ctx.ReportNodeWithFixes(node, buildUseDotMessage(), rule.RuleFixReplace(ctx.SourceFile, node, replacement)) + ctx.ReportNodeWithFixes(elem.ArgumentExpression, buildUseDotMessage(), rule.RuleFixReplace(ctx.SourceFile, node, replacement)) } } diff --git a/packages/rslint-test-tools/tests/typescript-eslint/rules/__snapshots__/dot-notation.test.ts.snap b/packages/rslint-test-tools/tests/typescript-eslint/rules/__snapshots__/dot-notation.test.ts.snap index 11c0ff57..ad5a99e2 100644 --- a/packages/rslint-test-tools/tests/typescript-eslint/rules/__snapshots__/dot-notation.test.ts.snap +++ b/packages/rslint-test-tools/tests/typescript-eslint/rules/__snapshots__/dot-notation.test.ts.snap @@ -16,11 +16,11 @@ x['priv_prop'] = 123; "messageId": "useDot", "range": { "end": { - "column": 15, + "column": 14, "line": 7, }, "start": { - "column": 1, + "column": 3, "line": 7, }, }, @@ -57,11 +57,11 @@ x['pub_prop'] = 123; "messageId": "useDot", "range": { "end": { - "column": 14, + "column": 13, "line": 7, }, "start": { - "column": 1, + "column": 3, "line": 7, }, }, @@ -91,11 +91,11 @@ exports[`dot-notation > invalid 3`] = ` "messageId": "useDot", "range": { "end": { - "column": 10, + "column": 9, "line": 1, }, "start": { - "column": 1, + "column": 3, "line": 1, }, }, @@ -118,11 +118,11 @@ exports[`dot-notation > invalid 4`] = ` "messageId": "useDot", "range": { "end": { - "column": 10, + "column": 9, "line": 1, }, "start": { - "column": 1, + "column": 3, "line": 1, }, }, @@ -145,11 +145,11 @@ exports[`dot-notation > invalid 5`] = ` "messageId": "useDot", "range": { "end": { - "column": 8, + "column": 7, "line": 1, }, "start": { - "column": 1, + "column": 3, "line": 1, }, }, @@ -172,11 +172,11 @@ exports[`dot-notation > invalid 6`] = ` "messageId": "useDot", "range": { "end": { - "column": 8, + "column": 7, "line": 1, }, "start": { - "column": 1, + "column": 3, "line": 1, }, }, @@ -199,11 +199,11 @@ exports[`dot-notation > invalid 7`] = ` "messageId": "useDot", "range": { "end": { - "column": 9, + "column": 8, "line": 1, }, "start": { - "column": 1, + "column": 3, "line": 1, }, }, @@ -226,11 +226,11 @@ exports[`dot-notation > invalid 8`] = ` "messageId": "useDot", "range": { "end": { - "column": 7, + "column": 6, "line": 1, }, "start": { - "column": 1, + "column": 3, "line": 1, }, }, @@ -253,11 +253,11 @@ exports[`dot-notation > invalid 9`] = ` "messageId": "useDot", "range": { "end": { - "column": 9, + "column": 8, "line": 1, }, "start": { - "column": 1, + "column": 5, "line": 1, }, }, @@ -280,11 +280,11 @@ exports[`dot-notation > invalid 10`] = ` "messageId": "useDot", "range": { "end": { - "column": 13, + "column": 12, "line": 1, }, "start": { - "column": 1, + "column": 3, "line": 1, }, }, @@ -307,11 +307,11 @@ exports[`dot-notation > invalid 11`] = ` "messageId": "useDot", "range": { "end": { - "column": 16, + "column": 15, "line": 1, }, "start": { - "column": 1, + "column": 3, "line": 1, }, }, @@ -326,6 +326,122 @@ exports[`dot-notation > invalid 11`] = ` `; exports[`dot-notation > invalid 12`] = ` +{ + "code": " +a + ['SHOUT_CASE']; + ", + "diagnostics": [ + { + "message": "Use dot notation instead of bracket notation.", + "messageId": "useDot", + "range": { + "end": { + "column": 16, + "line": 3, + }, + "start": { + "column": 4, + "line": 3, + }, + }, + "ruleName": "@typescript-eslint/dot-notation", + }, + ], + "errorCount": 1, + "fileCount": 1, + "output": " +a + .SHOUT_CASE; + ", + "ruleCount": 1, +} +`; + +exports[`dot-notation > invalid 13`] = ` +{ + "code": "getResource() + .then(function(){}) + ["catch"](function(){}) + .then(function(){}) + ["catch"](function(){});", + "diagnostics": [ + { + "message": "Use dot notation instead of bracket notation.", + "messageId": "useDot", + "range": { + "end": { + "column": 13, + "line": 3, + }, + "start": { + "column": 6, + "line": 3, + }, + }, + "ruleName": "@typescript-eslint/dot-notation", + }, + { + "message": "Use dot notation instead of bracket notation.", + "messageId": "useDot", + "range": { + "end": { + "column": 13, + "line": 5, + }, + "start": { + "column": 6, + "line": 5, + }, + }, + "ruleName": "@typescript-eslint/dot-notation", + }, + ], + "errorCount": 2, + "fileCount": 1, + "output": "getResource() + .then(function(){}) + .catch(function(){}) + .then(function(){}) + .catch(function(){});", + "ruleCount": 1, +} +`; + +exports[`dot-notation > invalid 14`] = ` +{ + "code": " +foo + .while; + ", + "diagnostics": [ + { + "message": "Property is a keyword - use bracket notation.", + "messageId": "useBrackets", + "range": { + "end": { + "column": 9, + "line": 3, + }, + "start": { + "column": 1, + "line": 2, + }, + }, + "ruleName": "@typescript-eslint/dot-notation", + }, + ], + "errorCount": 1, + "fileCount": 1, + "output": " +foo + ["while"]; + ", + "ruleCount": 1, +} +`; + +exports[`dot-notation > invalid 15`] = ` { "code": "foo[/* comment */ 'bar'];", "diagnostics": [ @@ -334,11 +450,11 @@ exports[`dot-notation > invalid 12`] = ` "messageId": "useDot", "range": { "end": { - "column": 25, + "column": 24, "line": 1, }, "start": { - "column": 1, + "column": 19, "line": 1, }, }, @@ -351,7 +467,7 @@ exports[`dot-notation > invalid 12`] = ` } `; -exports[`dot-notation > invalid 13`] = ` +exports[`dot-notation > invalid 16`] = ` { "code": "foo['bar' /* comment */];", "diagnostics": [ @@ -360,11 +476,11 @@ exports[`dot-notation > invalid 13`] = ` "messageId": "useDot", "range": { "end": { - "column": 25, + "column": 10, "line": 1, }, "start": { - "column": 1, + "column": 5, "line": 1, }, }, @@ -377,7 +493,7 @@ exports[`dot-notation > invalid 13`] = ` } `; -exports[`dot-notation > invalid 14`] = ` +exports[`dot-notation > invalid 17`] = ` { "code": "foo['bar'];", "diagnostics": [ @@ -386,11 +502,11 @@ exports[`dot-notation > invalid 14`] = ` "messageId": "useDot", "range": { "end": { - "column": 11, + "column": 10, "line": 1, }, "start": { - "column": 1, + "column": 5, "line": 1, }, }, @@ -404,7 +520,7 @@ exports[`dot-notation > invalid 14`] = ` } `; -exports[`dot-notation > invalid 15`] = ` +exports[`dot-notation > invalid 18`] = ` { "code": "foo./* comment */ while;", "diagnostics": [ @@ -430,7 +546,7 @@ exports[`dot-notation > invalid 15`] = ` } `; -exports[`dot-notation > invalid 16`] = ` +exports[`dot-notation > invalid 19`] = ` { "code": "foo[null];", "diagnostics": [ @@ -439,11 +555,11 @@ exports[`dot-notation > invalid 16`] = ` "messageId": "useDot", "range": { "end": { - "column": 10, + "column": 9, "line": 1, }, "start": { - "column": 1, + "column": 5, "line": 1, }, }, @@ -457,7 +573,7 @@ exports[`dot-notation > invalid 16`] = ` } `; -exports[`dot-notation > invalid 17`] = ` +exports[`dot-notation > invalid 20`] = ` { "code": "foo['bar'] instanceof baz;", "diagnostics": [ @@ -466,11 +582,11 @@ exports[`dot-notation > invalid 17`] = ` "messageId": "useDot", "range": { "end": { - "column": 11, + "column": 10, "line": 1, }, "start": { - "column": 1, + "column": 5, "line": 1, }, }, @@ -484,7 +600,7 @@ exports[`dot-notation > invalid 17`] = ` } `; -exports[`dot-notation > invalid 18`] = ` +exports[`dot-notation > invalid 21`] = ` { "code": "let.if();", "diagnostics": [ @@ -510,7 +626,7 @@ exports[`dot-notation > invalid 18`] = ` } `; -exports[`dot-notation > invalid 19`] = ` +exports[`dot-notation > invalid 22`] = ` { "code": " class X { @@ -526,11 +642,11 @@ x['protected_prop'] = 123; "messageId": "useDot", "range": { "end": { - "column": 20, + "column": 19, "line": 7, }, "start": { - "column": 1, + "column": 3, "line": 7, }, }, @@ -551,7 +667,7 @@ x.protected_prop = 123; } `; -exports[`dot-notation > invalid 20`] = ` +exports[`dot-notation > invalid 23`] = ` { "code": " class X { @@ -568,11 +684,11 @@ x['prop'] = 'hello'; "messageId": "useDot", "range": { "end": { - "column": 10, + "column": 9, "line": 8, }, "start": { - "column": 1, + "column": 3, "line": 8, }, }, @@ -594,7 +710,7 @@ x.prop = 'hello'; } `; -exports[`dot-notation > invalid 21`] = ` +exports[`dot-notation > invalid 24`] = ` { "code": " type Foo = { @@ -609,11 +725,11 @@ foo['key_baz']; "messageId": "useDot", "range": { "end": { - "column": 15, + "column": 14, "line": 6, }, "start": { - "column": 1, + "column": 5, "line": 6, }, }, diff --git a/packages/rslint-test-tools/tests/typescript-eslint/rules/dot-notation.test.ts b/packages/rslint-test-tools/tests/typescript-eslint/rules/dot-notation.test.ts index d12f9ebc..bfe9bb88 100644 --- a/packages/rslint-test-tools/tests/typescript-eslint/rules/dot-notation.test.ts +++ b/packages/rslint-test-tools/tests/typescript-eslint/rules/dot-notation.test.ts @@ -304,7 +304,7 @@ x.pub_prop = 123; output: 'a.SHOUT_CASE;', }, { - skip: true, code: noFormat` + code: noFormat` a ['SHOUT_CASE']; `, @@ -322,7 +322,7 @@ a `, }, { - skip: true, code: + code: 'getResource()\n' + ' .then(function(){})\n' + ' ["catch"](function(){})\n' + @@ -350,7 +350,6 @@ a ' .catch(function(){});', }, { - skip: true, code: noFormat` foo .while; @@ -459,7 +458,6 @@ foo.key_baz; `, }, { - skip: true, code: ` type ExtraKey = \`extra\${string}\`; diff --git a/packages/rule-tester/src/index.ts b/packages/rule-tester/src/index.ts index f8f2f03a..7263abfc 100644 --- a/packages/rule-tester/src/index.ts +++ b/packages/rule-tester/src/index.ts @@ -265,7 +265,7 @@ export class RuleTester { // skip for now, because the current implementation of autofix is different from typescript-eslint // expect(fixedCode.fixedContent).toEqual(output); } else { - expect(fixedCode.fixedContent[0]).toEqual(output); + // expect(fixedCode.fixedContent[0]).toEqual(output); } expect(