diff --git a/tests/fixtures/common.expected.messages.js b/tests/fixtures/common.expected.messages.js new file mode 100644 index 0000000..0488547 --- /dev/null +++ b/tests/fixtures/common.expected.messages.js @@ -0,0 +1,410 @@ +// To be honest: this file was auto-generated and not manually checked. +// Should be fine though as the outcome is exactly what is expected. +// (by checking in the IDE that all the autofixes work as assumed) + +const messages = [ + { + ruleId: "@stylistic/no-multi-spaces", + severity: 2, + message: "Multiple spaces found before '('.", + line: 1, + column: 3, + nodeType: "Punctuator", + messageId: "multipleSpaces", + endLine: 1, + endColumn: 9, + fix: { range: [2, 8], text: " " }, + }, + { + ruleId: "no-constant-condition", + severity: 2, + message: "Unexpected constant condition.", + line: 1, + column: 30, + nodeType: "ObjectExpression", + messageId: "unexpected", + endLine: 1, + endColumn: 32, + suppressions: [{ kind: "directive", justification: "" }], + }, + { + ruleId: "@stylistic/no-multi-spaces", + severity: 2, + message: "Multiple spaces found before ')'.", + line: 1, + column: 25, + nodeType: "Punctuator", + messageId: "multipleSpaces", + endLine: 1, + endColumn: 30, + fix: { range: [24, 29], text: " " }, + }, + { + ruleId: "@stylistic/space-in-parens", + severity: 2, + message: "There should be no space before this paren.", + line: 1, + column: 25, + nodeType: "Program", + messageId: "rejectedClosingSpace", + endLine: 1, + endColumn: 30, + fix: { range: [24, 29], text: "" }, + }, + { + ruleId: "@stylistic/padded-blocks", + severity: 2, + message: "Block must be padded by blank lines.", + line: 1, + column: 32, + nodeType: "BlockStatement", + messageId: "alwaysPadBlock", + endLine: 2, + endColumn: 5, + fix: { range: [32, 32], text: "\n" }, + }, + { + ruleId: "@stylistic/indent", + severity: 2, + message: "Expected indentation of 2 spaces but found 4.", + line: 2, + column: 1, + nodeType: "Identifier", + messageId: "wrongIndentation", + endLine: 2, + endColumn: 5, + fix: { range: [33, 37], text: " " }, + }, + { + ruleId: "@stylistic/quotes", + severity: 2, + message: "Strings must use doublequote.", + line: 2, + column: 17, + nodeType: "Literal", + messageId: "wrongQuotes", + endLine: 2, + endColumn: 29, + fix: { range: [49, 61], text: "\"Success 🎉\"" }, + }, + { + ruleId: "@stylistic/indent", + severity: 2, + message: "Expected indentation of 2 spaces but found 5.", + line: 3, + column: 1, + nodeType: "Identifier", + messageId: "wrongIndentation", + endLine: 3, + endColumn: 6, + fix: { range: [64, 69], text: " " }, + }, + { + ruleId: "@stylistic/quotes", + severity: 2, + message: "Strings must use doublequote.", + line: 3, + column: 8, + nodeType: "Literal", + messageId: "wrongQuotes", + endLine: 3, + endColumn: 15, + fix: { range: [71, 78], text: "\"#yeah\"" }, + }, + { + ruleId: "@stylistic/no-multi-spaces", + severity: 2, + message: "Multiple spaces found before ''/* eslint-disable */{}/* eslint-enable */''.", + line: 3, + column: 22, + nodeType: "String", + messageId: "multipleSpaces", + endLine: 3, + endColumn: 24, + fix: { range: [85, 87], text: " " }, + }, + { + ruleId: "@stylistic/space-in-parens", + severity: 2, + message: "There should be no space after this paren.", + line: 3, + column: 22, + nodeType: "Program", + messageId: "rejectedOpeningSpace", + endLine: 3, + endColumn: 24, + fix: { range: [85, 87], text: "" }, + }, + { + ruleId: "@stylistic/quotes", + severity: 2, + message: "Strings must use doublequote.", + line: 3, + column: 24, + nodeType: "Literal", + messageId: "wrongQuotes", + endLine: 4, + endColumn: 54, + fix: { + range: [87, 171], + text: `"<%= j render partial: 'yeah',\n` + + " locals: { cool: @cool } %>\"", + }, + }, + { + ruleId: "@stylistic/no-multi-spaces", + severity: 2, + message: "Multiple spaces found before ')'.", + line: 4, + column: 54, + nodeType: "Punctuator", + messageId: "multipleSpaces", + endLine: 4, + endColumn: 59, + fix: { range: [171, 176], text: " " }, + }, + { + ruleId: "@stylistic/space-in-parens", + severity: 2, + message: "There should be no space before this paren.", + line: 4, + column: 54, + nodeType: "Program", + messageId: "rejectedClosingSpace", + endLine: 4, + endColumn: 59, + fix: { range: [171, 176], text: "" }, + }, + { + ruleId: "@stylistic/padded-blocks", + severity: 2, + message: "Block must be padded by blank lines.", + line: 4, + column: 61, + nodeType: "BlockStatement", + messageId: "alwaysPadBlock", + endLine: 5, + endColumn: 3, + fix: { range: [181, 181], text: "\n" }, + }, + { + ruleId: "@stylistic/indent", + severity: 2, + message: "Expected indentation of 0 spaces but found 2.", + line: 5, + column: 1, + nodeType: "Punctuator", + messageId: "wrongIndentation", + endLine: 5, + endColumn: 3, + fix: { range: [179, 181], text: "" }, + }, + { + ruleId: "@stylistic/brace-style", + severity: 2, + message: "Closing curly brace does not appear on the same line as the subsequent block.", + line: 5, + column: 3, + nodeType: "Punctuator", + messageId: "nextLineClose", + endLine: 5, + endColumn: 4, + fix: { range: [182, 190], text: " " }, + }, + { + ruleId: "@stylistic/indent", + severity: 2, + message: "Expected indentation of 0 spaces but found 7.", + line: 6, + column: 1, + nodeType: "Keyword", + messageId: "wrongIndentation", + endLine: 6, + endColumn: 8, + fix: { range: [183, 190], text: "" }, + }, + { + ruleId: "@stylistic/padded-blocks", + severity: 2, + message: "Block must be padded by blank lines.", + line: 6, + column: 13, + nodeType: "BlockStatement", + messageId: "alwaysPadBlock", + endLine: 7, + endColumn: 5, + fix: { range: [196, 196], text: "\n" }, + }, + { + ruleId: "@stylistic/indent", + severity: 2, + message: "Expected indentation of 2 spaces but found 4.", + line: 7, + column: 1, + nodeType: "Identifier", + messageId: "wrongIndentation", + endLine: 7, + endColumn: 5, + fix: { range: [197, 201], text: " " }, + }, + { + ruleId: "@stylistic/padded-blocks", + severity: 2, + message: "Block must be padded by blank lines.", + line: 7, + column: 30, + nodeType: "BlockStatement", + messageId: "alwaysPadBlock", + endLine: 8, + endColumn: 9, + fix: { range: [235, 235], text: "\n" }, + }, + { + ruleId: "@stylistic/semi", + severity: 2, + message: "Missing semicolon.", + line: 7, + column: 30, + nodeType: "ExpressionStatement", + messageId: "missingSemi", + endLine: 8, + endColumn: 1, + fix: { range: [226, 226], text: ";" }, + }, + { + ruleId: "@stylistic/indent", + severity: 2, + message: "Expected indentation of 0 spaces but found 8.", + line: 8, + column: 1, + nodeType: "Punctuator", + messageId: "wrongIndentation", + endLine: 8, + endColumn: 9, + fix: { range: [227, 235], text: "" }, + }, + { + ruleId: "@stylistic/no-trailing-spaces", + severity: 2, + message: "Trailing spaces not allowed.", + line: 9, + column: 1, + nodeType: "Program", + messageId: "trailingSpace", + endLine: 9, + endColumn: 3, + fix: { range: [237, 239], text: "" }, + }, + { + ruleId: "@stylistic/indent", + severity: 2, + message: "Expected indentation of 0 spaces but found 2.", + line: 10, + column: 1, + nodeType: "Block", + messageId: "wrongIndentation", + endLine: 10, + endColumn: 3, + fix: { range: [240, 242], text: "" }, + }, + { + ruleId: "no-empty", + severity: 2, + message: "Empty block statement.", + line: 10, + column: 23, + nodeType: "BlockStatement", + messageId: "unexpected", + endLine: 10, + endColumn: 25, + suggestions: [ + { + messageId: "suggestComment", + data: { type: "block" }, + fix: { range: [248, 248], text: " /* empty */ " }, + desc: "Add comment inside empty block statement.", + }, + ], + suppressions: [{ kind: "directive", justification: "" }], + }, + { + ruleId: "@stylistic/indent", + severity: 2, + message: "Expected indentation of 0 spaces but found 4.", + line: 11, + column: 1, + nodeType: "Identifier", + messageId: "wrongIndentation", + endLine: 11, + endColumn: 5, + fix: { range: [266, 270], text: "" }, + }, + { + ruleId: "@stylistic/quotes", + severity: 2, + message: "Strings must use doublequote.", + line: 11, + column: 17, + nodeType: "Literal", + messageId: "wrongQuotes", + endLine: 11, + endColumn: 35, + fix: { range: [282, 300], text: "\"You are lucky 🍀\"" }, + }, + { + ruleId: "@stylistic/indent", + severity: 2, + message: "Expected indentation of 0 spaces but found 2.", + line: 12, + column: 1, + nodeType: "Block", + messageId: "wrongIndentation", + endLine: 12, + endColumn: 3, + fix: { range: [303, 305], text: "" }, + }, + { + ruleId: "no-empty", + severity: 2, + message: "Empty block statement.", + line: 12, + column: 23, + nodeType: "BlockStatement", + messageId: "unexpected", + endLine: 12, + endColumn: 25, + suggestions: [ + { + messageId: "suggestComment", + data: { type: "block" }, + fix: { range: [329, 329], text: " /* empty */ " }, + desc: "Add comment inside empty block statement.", + }, + ], + suppressions: [{ kind: "directive", justification: "" }], + }, + { + ruleId: "@stylistic/no-trailing-spaces", + severity: 2, + message: "Trailing spaces not allowed.", + line: 13, + column: 1, + nodeType: "Program", + messageId: "trailingSpace", + endLine: 13, + endColumn: 3, + fix: { range: [315, 317], text: "" }, + }, + { + ruleId: "@stylistic/eol-last", + severity: 2, + message: "Newline required at end of file but not found.", + line: 13, + column: 3, + nodeType: "Program", + messageId: "missing", + fix: { range: [317, 317], text: "\n" }, + }, +]; + +module.exports = messages; diff --git a/tests/fixtures/common.messages.js b/tests/fixtures/common.messages.js new file mode 100644 index 0000000..a8363fc --- /dev/null +++ b/tests/fixtures/common.messages.js @@ -0,0 +1,405 @@ +const messages = [ + { + ruleId: "@stylistic/no-multi-spaces", + severity: 2, + message: "Multiple spaces found before '('.", + line: 1, + column: 3, + nodeType: "Punctuator", + messageId: "multipleSpaces", + endLine: 1, + endColumn: 9, + fix: { range: [2, 8], text: " " }, + }, + { + ruleId: "no-constant-condition", + severity: 2, + message: "Unexpected constant condition.", + line: 1, + column: 30, + nodeType: "ObjectExpression", + messageId: "unexpected", + endLine: 1, + endColumn: 32, + suppressions: [{ kind: "directive", justification: "" }], + }, + { + ruleId: "@stylistic/no-multi-spaces", + severity: 2, + message: "Multiple spaces found before ')'.", + line: 1, + column: 51, + nodeType: "Punctuator", + messageId: "multipleSpaces", + endLine: 1, + endColumn: 56, + fix: { range: [50, 55], text: " " }, + }, + { + ruleId: "@stylistic/space-in-parens", + severity: 2, + message: "There should be no space before this paren.", + line: 1, + column: 51, + nodeType: "Program", + messageId: "rejectedClosingSpace", + endLine: 1, + endColumn: 56, + fix: { range: [50, 55], text: "" }, + }, + { + ruleId: "@stylistic/padded-blocks", + severity: 2, + message: "Block must be padded by blank lines.", + line: 1, + column: 58, + nodeType: "BlockStatement", + messageId: "alwaysPadBlock", + endLine: 2, + endColumn: 5, + fix: { range: [58, 58], text: "\n" }, + }, + { + ruleId: "@stylistic/indent", + severity: 2, + message: "Expected indentation of 2 spaces but found 4.", + line: 2, + column: 1, + nodeType: "Identifier", + messageId: "wrongIndentation", + endLine: 2, + endColumn: 5, + fix: { range: [59, 63], text: " " }, + }, + { + ruleId: "@stylistic/quotes", + severity: 2, + message: "Strings must use doublequote.", + line: 2, + column: 17, + nodeType: "Literal", + messageId: "wrongQuotes", + endLine: 2, + endColumn: 29, + fix: { range: [75, 87], text: "\"Success 🎉\"" }, + }, + { + ruleId: "@stylistic/indent", + severity: 2, + message: "Expected indentation of 2 spaces but found 5.", + line: 3, + column: 1, + nodeType: "Identifier", + messageId: "wrongIndentation", + endLine: 3, + endColumn: 6, + fix: { range: [90, 95], text: " " }, + }, + { + ruleId: "@stylistic/quotes", + severity: 2, + message: "Strings must use doublequote.", + line: 3, + column: 8, + nodeType: "Literal", + messageId: "wrongQuotes", + endLine: 3, + endColumn: 15, + fix: { range: [97, 104], text: "\"#yeah\"" }, + }, + { + ruleId: "@stylistic/no-multi-spaces", + severity: 2, + message: "Multiple spaces found before ''/* eslint-disable */{}/* eslint-enable */''.", + line: 3, + column: 22, + nodeType: "String", + messageId: "multipleSpaces", + endLine: 3, + endColumn: 24, + fix: { range: [111, 113], text: " " }, + }, + { + ruleId: "@stylistic/space-in-parens", + severity: 2, + message: "There should be no space after this paren.", + line: 3, + column: 22, + nodeType: "Program", + messageId: "rejectedOpeningSpace", + endLine: 3, + endColumn: 24, + fix: { range: [111, 113], text: "" }, + }, + { + ruleId: "@stylistic/quotes", + severity: 2, + message: "Strings must use doublequote.", + line: 3, + column: 24, + nodeType: "Literal", + messageId: "wrongQuotes", + endLine: 3, + endColumn: 67, + fix: { + range: [113, 156], + text: "\"/* eslint-disable */{}/* eslint-enable */\"", + }, + }, + { + ruleId: "@stylistic/no-multi-spaces", + severity: 2, + message: "Multiple spaces found before ')'.", + line: 3, + column: 67, + nodeType: "Punctuator", + messageId: "multipleSpaces", + endLine: 3, + endColumn: 72, + fix: { range: [156, 161], text: " " }, + }, + { + ruleId: "@stylistic/space-in-parens", + severity: 2, + message: "There should be no space before this paren.", + line: 3, + column: 67, + nodeType: "Program", + messageId: "rejectedClosingSpace", + endLine: 3, + endColumn: 72, + fix: { range: [156, 161], text: "" }, + }, + { + ruleId: "@stylistic/padded-blocks", + severity: 2, + message: "Block must be padded by blank lines.", + line: 3, + column: 74, + nodeType: "BlockStatement", + messageId: "alwaysPadBlock", + endLine: 4, + endColumn: 3, + fix: { range: [166, 166], text: "\n" }, + }, + { + ruleId: "@stylistic/indent", + severity: 2, + message: "Expected indentation of 0 spaces but found 2.", + line: 4, + column: 1, + nodeType: "Punctuator", + messageId: "wrongIndentation", + endLine: 4, + endColumn: 3, + fix: { range: [164, 166], text: "" }, + }, + { + ruleId: "@stylistic/brace-style", + severity: 2, + message: "Closing curly brace does not appear on the same line as the subsequent block.", + line: 4, + column: 3, + nodeType: "Punctuator", + messageId: "nextLineClose", + endLine: 4, + endColumn: 4, + fix: { range: [167, 175], text: " " }, + }, + { + ruleId: "@stylistic/indent", + severity: 2, + message: "Expected indentation of 0 spaces but found 7.", + line: 5, + column: 1, + nodeType: "Keyword", + messageId: "wrongIndentation", + endLine: 5, + endColumn: 8, + fix: { range: [168, 175], text: "" }, + }, + { + ruleId: "@stylistic/padded-blocks", + severity: 2, + message: "Block must be padded by blank lines.", + line: 5, + column: 13, + nodeType: "BlockStatement", + messageId: "alwaysPadBlock", + endLine: 6, + endColumn: 5, + fix: { range: [181, 181], text: "\n" }, + }, + { + ruleId: "@stylistic/indent", + severity: 2, + message: "Expected indentation of 2 spaces but found 4.", + line: 6, + column: 1, + nodeType: "Identifier", + messageId: "wrongIndentation", + endLine: 6, + endColumn: 5, + fix: { range: [182, 186], text: " " }, + }, + { + ruleId: "@stylistic/padded-blocks", + severity: 2, + message: "Block must be padded by blank lines.", + line: 6, + column: 30, + nodeType: "BlockStatement", + messageId: "alwaysPadBlock", + endLine: 7, + endColumn: 9, + fix: { range: [220, 220], text: "\n" }, + }, + { + ruleId: "@stylistic/semi", + severity: 2, + message: "Missing semicolon.", + line: 6, + column: 30, + nodeType: "ExpressionStatement", + messageId: "missingSemi", + endLine: 7, + endColumn: 1, + fix: { range: [211, 211], text: ";" }, + }, + { + ruleId: "@stylistic/indent", + severity: 2, + message: "Expected indentation of 0 spaces but found 8.", + line: 7, + column: 1, + nodeType: "Punctuator", + messageId: "wrongIndentation", + endLine: 7, + endColumn: 9, + fix: { range: [212, 220], text: "" }, + }, + { + ruleId: "@stylistic/no-trailing-spaces", + severity: 2, + message: "Trailing spaces not allowed.", + line: 8, + column: 1, + nodeType: "Program", + messageId: "trailingSpace", + endLine: 8, + endColumn: 3, + fix: { range: [222, 224], text: "" }, + }, + { + ruleId: "@stylistic/indent", + severity: 2, + message: "Expected indentation of 0 spaces but found 2.", + line: 9, + column: 1, + nodeType: "Block", + messageId: "wrongIndentation", + endLine: 9, + endColumn: 3, + fix: { range: [225, 227], text: "" }, + }, + { + ruleId: "no-empty", + severity: 2, + message: "Empty block statement.", + line: 9, + column: 23, + nodeType: "BlockStatement", + messageId: "unexpected", + endLine: 9, + endColumn: 25, + suggestions: [ + { + messageId: "suggestComment", + data: { type: "block" }, + fix: { range: [248, 248], text: " /* empty */ " }, + desc: "Add comment inside empty block statement.", + }, + ], + suppressions: [{ kind: "directive", justification: "" }], + }, + { + ruleId: "@stylistic/indent", + severity: 2, + message: "Expected indentation of 0 spaces but found 4.", + line: 10, + column: 1, + nodeType: "Identifier", + messageId: "wrongIndentation", + endLine: 10, + endColumn: 5, + fix: { range: [269, 273], text: "" }, + }, + { + ruleId: "@stylistic/quotes", + severity: 2, + message: "Strings must use doublequote.", + line: 10, + column: 17, + nodeType: "Literal", + messageId: "wrongQuotes", + endLine: 10, + endColumn: 35, + fix: { range: [285, 303], text: "\"You are lucky 🍀\"" }, + }, + { + ruleId: "@stylistic/indent", + severity: 2, + message: "Expected indentation of 0 spaces but found 2.", + line: 11, + column: 1, + nodeType: "Block", + messageId: "wrongIndentation", + endLine: 11, + endColumn: 3, + fix: { range: [306, 308], text: "" }, + }, + { + ruleId: "no-empty", + severity: 2, + message: "Empty block statement.", + line: 11, + column: 23, + nodeType: "BlockStatement", + messageId: "unexpected", + endLine: 11, + endColumn: 25, + suggestions: [ + { + messageId: "suggestComment", + data: { type: "block" }, + fix: { range: [329, 329], text: " /* empty */ " }, + desc: "Add comment inside empty block statement.", + }, + ], + suppressions: [{ kind: "directive", justification: "" }], + }, + { + ruleId: "@stylistic/no-trailing-spaces", + severity: 2, + message: "Trailing spaces not allowed.", + line: 12, + column: 1, + nodeType: "Program", + messageId: "trailingSpace", + endLine: 12, + endColumn: 3, + fix: { range: [350, 352], text: "" }, + }, + { + ruleId: "@stylistic/eol-last", + severity: 2, + message: "Newline required at end of file but not found.", + line: 12, + column: 3, + nodeType: "Program", + messageId: "missing", + fix: { range: [352, 352], text: "\n" }, + }, +]; + +module.exports = messages; diff --git a/tests/fixtures/each-do.expected.messages.js b/tests/fixtures/each-do.expected.messages.js new file mode 100644 index 0000000..dc0e209 --- /dev/null +++ b/tests/fixtures/each-do.expected.messages.js @@ -0,0 +1,69 @@ +const messages = [ + { + ruleId: "no-empty", + severity: 2, + message: "Empty block statement.", + line: 1, + column: 21, + nodeType: "BlockStatement", + messageId: "unexpected", + endLine: 1, + endColumn: 23, + suggestions: [ + { + messageId: "suggestComment", + data: { type: "block" }, + fix: { range: [21, 21], text: " /* empty */ " }, + desc: "Add comment inside empty block statement.", + }, + ], + suppressions: [{ kind: "directive", justification: "" }], + }, + { + ruleId: "@stylistic/quotes", + severity: 2, + message: "Strings must use doublequote.", + line: 2, + column: 13, + nodeType: "Literal", + messageId: "wrongQuotes", + endLine: 2, + endColumn: 23, + fix: { + range: [37, 47], + text: "\"<%= j %>\"", + }, + }, + { + ruleId: "no-empty", + severity: 2, + message: "Empty block statement.", + line: 3, + column: 21, + nodeType: "BlockStatement", + messageId: "unexpected", + endLine: 3, + endColumn: 23, + suggestions: [ + { + messageId: "suggestComment", + data: { type: "block" }, + fix: { range: [134, 134], text: " /* empty */ " }, + desc: "Add comment inside empty block statement.", + }, + ], + suppressions: [{ kind: "directive", justification: "" }], + }, + { + ruleId: "@stylistic/eol-last", + severity: 2, + message: "Newline required at end of file but not found.", + line: 3, + column: 10, + nodeType: "Program", + messageId: "missing", + fix: { range: [72, 72], text: "\n" }, + }, +]; + +module.exports = messages; diff --git a/tests/fixtures/each-do.messages.js b/tests/fixtures/each-do.messages.js new file mode 100644 index 0000000..d1060e3 --- /dev/null +++ b/tests/fixtures/each-do.messages.js @@ -0,0 +1,69 @@ +const messages = [ + { + ruleId: "no-empty", + severity: 2, + message: "Empty block statement.", + line: 1, + column: 21, + nodeType: "BlockStatement", + messageId: "unexpected", + endLine: 1, + endColumn: 23, + suggestions: [ + { + messageId: "suggestComment", + data: { type: "block" }, + fix: { range: [21, 21], text: " /* empty */ " }, + desc: "Add comment inside empty block statement.", + }, + ], + suppressions: [{ kind: "directive", justification: "" }], + }, + { + ruleId: "@stylistic/quotes", + severity: 2, + message: "Strings must use doublequote.", + line: 2, + column: 13, + nodeType: "Literal", + messageId: "wrongQuotes", + endLine: 2, + endColumn: 56, + fix: { + range: [54, 97], + text: "\"/* eslint-disable */{}/* eslint-enable */\"", + }, + }, + { + ruleId: "no-empty", + severity: 2, + message: "Empty block statement.", + line: 3, + column: 21, + nodeType: "BlockStatement", + messageId: "unexpected", + endLine: 3, + endColumn: 23, + suggestions: [ + { + messageId: "suggestComment", + data: { type: "block" }, + fix: { range: [134, 134], text: " /* empty */ " }, + desc: "Add comment inside empty block statement.", + }, + ], + suppressions: [{ kind: "directive", justification: "" }], + }, + { + ruleId: "@stylistic/eol-last", + severity: 2, + message: "Newline required at end of file but not found.", + line: 3, + column: 42, + nodeType: "Program", + messageId: "missing", + fix: { range: [154, 154], text: "\n" }, + }, +]; + +module.exports = messages; diff --git a/tests/fixtures/multi-line.expected.messages.js b/tests/fixtures/multi-line.expected.messages.js new file mode 100644 index 0000000..91db8a6 --- /dev/null +++ b/tests/fixtures/multi-line.expected.messages.js @@ -0,0 +1,81 @@ +const messages = [ + { + ruleId: "@stylistic/indent", + severity: 2, + message: "Expected indentation of 0 spaces but found 4.", + line: 1, + column: 1, + nodeType: "Keyword", + messageId: "wrongIndentation", + endLine: 1, + endColumn: 5, + fix: { range: [0, 4], text: "" }, + }, + { + ruleId: "no-unused-vars", + severity: 1, + message: "'a' is assigned a value but never used.", + line: 1, + column: 11, + nodeType: "Identifier", + messageId: "unusedVar", + endLine: 1, + endColumn: 12, + }, + { + ruleId: "@stylistic/semi", + severity: 2, + message: "Missing semicolon.", + line: 1, + column: 23, + nodeType: "VariableDeclaration", + messageId: "missingSemi", + endLine: 2, + endColumn: 1, + fix: { range: [22, 22], text: ";" }, + }, + { + ruleId: "no-empty", + severity: 2, + message: "Empty block statement.", + line: 2, + column: 21, + nodeType: "BlockStatement", + messageId: "unexpected", + endLine: 2, + endColumn: 23, + suggestions: [ + { + messageId: "suggestComment", + data: { type: "block" }, + fix: { range: [44, 44], text: " /* empty */ " }, + desc: "Add comment inside empty block statement.", + }, + ], + suppressions: [{ kind: "directive", justification: "" }], + }, + { + ruleId: "@stylistic/indent", + severity: 2, + message: "Expected indentation of 0 spaces but found 1.", + line: 5, + column: 1, + nodeType: "Identifier", + messageId: "wrongIndentation", + endLine: 5, + endColumn: 2, + fix: { range: [144, 145], text: "" }, + }, + { + ruleId: "@stylistic/eol-last", + severity: 2, + message: "Newline required at end of file but not found.", + line: 5, + column: 28, + nodeType: "Program", + messageId: "missing", + fix: { range: [171, 171], text: "\n" }, + }, +]; + +module.exports = messages; diff --git a/tests/fixtures/multi-line.messages.js b/tests/fixtures/multi-line.messages.js new file mode 100644 index 0000000..46efaeb --- /dev/null +++ b/tests/fixtures/multi-line.messages.js @@ -0,0 +1,81 @@ +const messages = [ + { + ruleId: "@stylistic/indent", + severity: 2, + message: "Expected indentation of 0 spaces but found 4.", + line: 1, + column: 1, + nodeType: "Keyword", + messageId: "wrongIndentation", + endLine: 1, + endColumn: 5, + fix: { range: [0, 4], text: "" }, + }, + { + ruleId: "no-unused-vars", + severity: 1, + message: "'a' is assigned a value but never used.", + line: 1, + column: 11, + nodeType: "Identifier", + messageId: "unusedVar", + endLine: 1, + endColumn: 12, + }, + { + ruleId: "@stylistic/semi", + severity: 2, + message: "Missing semicolon.", + line: 1, + column: 23, + nodeType: "VariableDeclaration", + messageId: "missingSemi", + endLine: 2, + endColumn: 1, + fix: { range: [22, 22], text: ";" }, + }, + { + ruleId: "no-empty", + severity: 2, + message: "Empty block statement.", + line: 2, + column: 21, + nodeType: "BlockStatement", + messageId: "unexpected", + endLine: 2, + endColumn: 23, + suggestions: [ + { + messageId: "suggestComment", + data: { type: "block" }, + fix: { range: [44, 44], text: " /* empty */ " }, + desc: "Add comment inside empty block statement.", + }, + ], + suppressions: [{ kind: "directive", justification: "" }], + }, + { + ruleId: "@stylistic/indent", + severity: 2, + message: "Expected indentation of 0 spaces but found 1.", + line: 3, + column: 1, + nodeType: "Identifier", + messageId: "wrongIndentation", + endLine: 3, + endColumn: 2, + fix: { range: [65, 66], text: "" }, + }, + { + ruleId: "@stylistic/eol-last", + severity: 2, + message: "Newline required at end of file but not found.", + line: 3, + column: 28, + nodeType: "Program", + messageId: "missing", + fix: { range: [92, 92], text: "\n" }, + }, +]; + +module.exports = messages; diff --git a/tests/fixtures/multiple-erb-in-one-line.expected.messages.js b/tests/fixtures/multiple-erb-in-one-line.expected.messages.js new file mode 100644 index 0000000..9c46479 --- /dev/null +++ b/tests/fixtures/multiple-erb-in-one-line.expected.messages.js @@ -0,0 +1,215 @@ +const messages = [ + { + ruleId: "@stylistic/max-len", + severity: 2, + message: "This line has a length of 188. Maximum allowed is 100.", + line: 1, + column: 1, + nodeType: "Program", + messageId: "max", + endLine: 1, + endColumn: 112, + }, + { + ruleId: "@stylistic/func-call-spacing", + severity: 2, + message: "Unexpected whitespace between function name and paren.", + line: 1, + column: 9, + nodeType: "CallExpression", + messageId: "unexpectedWhitespace", + fix: { range: [11, 12], text: "" }, + }, + { + ruleId: "@stylistic/function-call-spacing", + severity: 2, + message: "Unexpected whitespace between function name and paren.", + line: 1, + column: 9, + nodeType: "CallExpression", + messageId: "unexpectedWhitespace", + fix: { range: [11, 12], text: "" }, + }, + { + ruleId: "@stylistic/semi-spacing", + severity: 2, + message: "Missing whitespace after semicolon.", + line: 1, + column: 20, + nodeType: "ExpressionStatement", + messageId: "missingWhitespaceAfter", + endLine: 1, + endColumn: 21, + fix: { range: [20, 20], text: " " }, + }, + { + ruleId: "@stylistic/space-before-blocks", + severity: 2, + message: "Missing space before opening brace.", + line: 1, + column: 41, + nodeType: "BlockStatement", + messageId: "missingSpace", + endLine: 1, + endColumn: 43, + fix: { range: [40, 40], text: " " }, + suppressions: [{ kind: "directive", justification: "" }], + }, + { + ruleId: "no-empty", + severity: 2, + message: "Empty block statement.", + line: 1, + column: 41, + nodeType: "BlockStatement", + messageId: "unexpected", + endLine: 1, + endColumn: 43, + suggestions: [ + { + messageId: "suggestComment", + data: { type: "block" }, + fix: { range: [41, 41], text: " /* empty */ " }, + desc: "Add comment inside empty block statement.", + }, + ], + suppressions: [{ kind: "directive", justification: "" }], + }, + { + ruleId: "@stylistic/max-statements-per-line", + severity: 2, + message: "This line has 3 statements. Maximum allowed is 1.", + line: 1, + column: 45, + nodeType: "ExpressionStatement", + messageId: "exceed", + endLine: 1, + endColumn: 69, + }, + { + ruleId: "@stylistic/quotes", + severity: 2, + message: "Strings must use doublequote.", + line: 1, + column: 57, + nodeType: "Literal", + messageId: "wrongQuotes", + endLine: 1, + endColumn: 67, + fix: { range: [56, 66], text: "\"whatever\"" }, + }, + { + ruleId: "@stylistic/semi-spacing", + severity: 2, + message: "Missing whitespace after semicolon.", + line: 1, + column: 68, + nodeType: "ExpressionStatement", + messageId: "missingWhitespaceAfter", + endLine: 1, + endColumn: 69, + fix: { range: [68, 68], text: " " }, + }, + { + ruleId: "@stylistic/space-before-blocks", + severity: 2, + message: "Missing space before opening brace.", + line: 1, + column: 89, + nodeType: "BlockStatement", + messageId: "missingSpace", + endLine: 1, + endColumn: 91, + fix: { range: [88, 88], text: " " }, + suppressions: [{ kind: "directive", justification: "" }], + }, + { + ruleId: "no-empty", + severity: 2, + message: "Empty block statement.", + line: 1, + column: 89, + nodeType: "BlockStatement", + messageId: "unexpected", + endLine: 1, + endColumn: 91, + suggestions: [ + { + messageId: "suggestComment", + data: { type: "block" }, + fix: { range: [106, 106], text: " /* empty */ " }, + desc: "Add comment inside empty block statement.", + }, + ], + suppressions: [{ kind: "directive", justification: "" }], + }, + { + ruleId: "@stylistic/quotes", + severity: 2, + message: "Strings must use doublequote.", + line: 1, + column: 95, + nodeType: "Literal", + messageId: "wrongQuotes", + endLine: 1, + endColumn: 101, + fix: { range: [94, 100], text: "\"true\"" }, + }, + { + ruleId: "@stylistic/semi-spacing", + severity: 2, + message: "Missing whitespace after semicolon.", + line: 1, + column: 102, + nodeType: "ExpressionStatement", + messageId: "missingWhitespaceAfter", + endLine: 1, + endColumn: 103, + fix: { range: [102, 102], text: " " }, + }, + { + ruleId: "@stylistic/space-before-blocks", + severity: 2, + message: "Missing space before opening brace.", + line: 1, + column: 123, + nodeType: "BlockStatement", + messageId: "missingSpace", + endLine: 1, + endColumn: 125, + fix: { range: [122, 122], text: " " }, + suppressions: [{ kind: "directive", justification: "" }], + }, + { + ruleId: "no-empty", + severity: 2, + message: "Empty block statement.", + line: 1, + column: 123, + nodeType: "BlockStatement", + messageId: "unexpected", + endLine: 1, + endColumn: 125, + suggestions: [ + { + messageId: "suggestComment", + data: { type: "block" }, + fix: { range: [168, 168], text: " /* empty */ " }, + desc: "Add comment inside empty block statement.", + }, + ], + suppressions: [{ kind: "directive", justification: "" }], + }, + { + ruleId: "@stylistic/eol-last", + severity: 2, + message: "Newline required at end of file but not found.", + line: 1, + column: 112, + nodeType: "Program", + messageId: "missing", + fix: { range: [111, 111], text: "\n" }, + }, +]; + +module.exports = messages; diff --git a/tests/fixtures/multiple-erb-in-one-line.messages.js b/tests/fixtures/multiple-erb-in-one-line.messages.js new file mode 100644 index 0000000..f316af8 --- /dev/null +++ b/tests/fixtures/multiple-erb-in-one-line.messages.js @@ -0,0 +1,215 @@ +const messages = [ + { + ruleId: "@stylistic/max-len", + severity: 2, + message: "This line has a length of 188. Maximum allowed is 100.", + line: 1, + column: 1, + nodeType: "Program", + messageId: "max", + endLine: 1, + endColumn: 189, + }, + { + ruleId: "@stylistic/func-call-spacing", + severity: 2, + message: "Unexpected whitespace between function name and paren.", + line: 1, + column: 9, + nodeType: "CallExpression", + messageId: "unexpectedWhitespace", + fix: { range: [11, 12], text: "" }, + }, + { + ruleId: "@stylistic/function-call-spacing", + severity: 2, + message: "Unexpected whitespace between function name and paren.", + line: 1, + column: 9, + nodeType: "CallExpression", + messageId: "unexpectedWhitespace", + fix: { range: [11, 12], text: "" }, + }, + { + ruleId: "@stylistic/semi-spacing", + severity: 2, + message: "Missing whitespace after semicolon.", + line: 1, + column: 20, + nodeType: "ExpressionStatement", + messageId: "missingWhitespaceAfter", + endLine: 1, + endColumn: 21, + fix: { range: [20, 20], text: " " }, + }, + { + ruleId: "@stylistic/space-before-blocks", + severity: 2, + message: "Missing space before opening brace.", + line: 1, + column: 41, + nodeType: "BlockStatement", + messageId: "missingSpace", + endLine: 1, + endColumn: 43, + fix: { range: [40, 40], text: " " }, + suppressions: [{ kind: "directive", justification: "" }], + }, + { + ruleId: "no-empty", + severity: 2, + message: "Empty block statement.", + line: 1, + column: 41, + nodeType: "BlockStatement", + messageId: "unexpected", + endLine: 1, + endColumn: 43, + suggestions: [ + { + messageId: "suggestComment", + data: { type: "block" }, + fix: { range: [41, 41], text: " /* empty */ " }, + desc: "Add comment inside empty block statement.", + }, + ], + suppressions: [{ kind: "directive", justification: "" }], + }, + { + ruleId: "@stylistic/max-statements-per-line", + severity: 2, + message: "This line has 3 statements. Maximum allowed is 1.", + line: 1, + column: 62, + nodeType: "ExpressionStatement", + messageId: "exceed", + endLine: 1, + endColumn: 86, + }, + { + ruleId: "@stylistic/quotes", + severity: 2, + message: "Strings must use doublequote.", + line: 1, + column: 74, + nodeType: "Literal", + messageId: "wrongQuotes", + endLine: 1, + endColumn: 84, + fix: { range: [73, 83], text: "\"whatever\"" }, + }, + { + ruleId: "@stylistic/semi-spacing", + severity: 2, + message: "Missing whitespace after semicolon.", + line: 1, + column: 85, + nodeType: "ExpressionStatement", + messageId: "missingWhitespaceAfter", + endLine: 1, + endColumn: 86, + fix: { range: [85, 85], text: " " }, + }, + { + ruleId: "@stylistic/space-before-blocks", + severity: 2, + message: "Missing space before opening brace.", + line: 1, + column: 106, + nodeType: "BlockStatement", + messageId: "missingSpace", + endLine: 1, + endColumn: 108, + fix: { range: [105, 105], text: " " }, + suppressions: [{ kind: "directive", justification: "" }], + }, + { + ruleId: "no-empty", + severity: 2, + message: "Empty block statement.", + line: 1, + column: 106, + nodeType: "BlockStatement", + messageId: "unexpected", + endLine: 1, + endColumn: 108, + suggestions: [ + { + messageId: "suggestComment", + data: { type: "block" }, + fix: { range: [106, 106], text: " /* empty */ " }, + desc: "Add comment inside empty block statement.", + }, + ], + suppressions: [{ kind: "directive", justification: "" }], + }, + { + ruleId: "@stylistic/quotes", + severity: 2, + message: "Strings must use doublequote.", + line: 1, + column: 140, + nodeType: "Literal", + messageId: "wrongQuotes", + endLine: 1, + endColumn: 146, + fix: { range: [139, 145], text: "\"true\"" }, + }, + { + ruleId: "@stylistic/semi-spacing", + severity: 2, + message: "Missing whitespace after semicolon.", + line: 1, + column: 147, + nodeType: "ExpressionStatement", + messageId: "missingWhitespaceAfter", + endLine: 1, + endColumn: 148, + fix: { range: [147, 147], text: " " }, + }, + { + ruleId: "@stylistic/space-before-blocks", + severity: 2, + message: "Missing space before opening brace.", + line: 1, + column: 168, + nodeType: "BlockStatement", + messageId: "missingSpace", + endLine: 1, + endColumn: 170, + fix: { range: [167, 167], text: " " }, + suppressions: [{ kind: "directive", justification: "" }], + }, + { + ruleId: "no-empty", + severity: 2, + message: "Empty block statement.", + line: 1, + column: 168, + nodeType: "BlockStatement", + messageId: "unexpected", + endLine: 1, + endColumn: 170, + suggestions: [ + { + messageId: "suggestComment", + data: { type: "block" }, + fix: { range: [168, 168], text: " /* empty */ " }, + desc: "Add comment inside empty block statement.", + }, + ], + suppressions: [{ kind: "directive", justification: "" }], + }, + { + ruleId: "@stylistic/eol-last", + severity: 2, + message: "Newline required at end of file but not found.", + line: 1, + column: 189, + nodeType: "Program", + messageId: "missing", + fix: { range: [188, 188], text: "\n" }, + }, +]; + +module.exports = messages; diff --git a/tests/fixtures/one-liner.expected.messages.js b/tests/fixtures/one-liner.expected.messages.js new file mode 100644 index 0000000..a920e21 --- /dev/null +++ b/tests/fixtures/one-liner.expected.messages.js @@ -0,0 +1,29 @@ +const messages = [ + { + ruleId: "@stylistic/quotes", + severity: 2, + message: "Strings must use doublequote.", + line: 1, + column: 3, + nodeType: "Literal", + messageId: "wrongQuotes", + endLine: 1, + endColumn: 15, + fix: { + range: [2, 14], + text: "\"#<%= id %>\"", + }, + }, + { + ruleId: "@stylistic/eol-last", + severity: 2, + message: "Newline required at end of file but not found.", + line: 1, + column: 24, + nodeType: "Program", + messageId: "missing", + fix: { range: [23, 23], text: "\n" }, + }, +]; + +module.exports = messages; diff --git a/tests/fixtures/one-liner.messages.js b/tests/fixtures/one-liner.messages.js new file mode 100644 index 0000000..f51be51 --- /dev/null +++ b/tests/fixtures/one-liner.messages.js @@ -0,0 +1,29 @@ +const messages = [ + { + ruleId: "@stylistic/quotes", + severity: 2, + message: "Strings must use doublequote.", + line: 1, + column: 3, + nodeType: "Literal", + messageId: "wrongQuotes", + endLine: 1, + endColumn: 47, + fix: { + range: [2, 46], + text: "\"#/* eslint-disable */{}/* eslint-enable */\"", + }, + }, + { + ruleId: "@stylistic/eol-last", + severity: 2, + message: "Newline required at end of file but not found.", + line: 1, + column: 56, + nodeType: "Program", + messageId: "missing", + fix: { range: [55, 55], text: "\n" }, + }, +]; + +module.exports = messages; diff --git a/tests/postprocess.js b/tests/postprocess.js new file mode 100644 index 0000000..0484cbf --- /dev/null +++ b/tests/postprocess.js @@ -0,0 +1,41 @@ +const fs = require("fs"); + +const assert = require("chai").assert; +const pre = require("../lib/preprocess.js"); +const post = require("../lib/postprocess.js"); +const cache = require("../lib/cache.js"); + +describe("postprocess", () => { + it("deletes file from cache after postprocessing", () => { + const text = `console.log("Hello world!");`; + const name = "testfile.js"; + + pre(text, name); + assert.exists(cache.get(name)); + assert.isNotEmpty(cache.get(name)); + + post([[]], name); + assert.isUndefined(cache.get(name)); + }); + + const mapFiles = [ + "one-liner", + "common", + "each-do", + "multi-line", + "multiple-erb-in-one-line", + ]; + mapFiles.forEach((name) => { + it(`correctly maps location from offset map on ${name}.js`, () => { + const filename = `tests/fixtures/${name}.js`; + const text = fs.readFileSync(filename, "utf-8"); + pre(text, filename); + + const esLintMessages = require(`../tests/fixtures/${name}.messages.js`); + + const finalMessages = post([esLintMessages], filename); + const expectedMessages = require(`../tests/fixtures/${name}.expected.messages.js`); + assert.deepEqual(expectedMessages, finalMessages); + }); + }); +}); diff --git a/tests/processor.js b/tests/preprocess.js similarity index 100% rename from tests/processor.js rename to tests/preprocess.js