Permalink
Browse files

Breaking: remove `source` property from linting messages (fixes #7358) (

  • Loading branch information...
not-an-aardvark committed Mar 22, 2018
1 parent e4c3b3c commit 27e3f24d88a405bb64531d26d64eb356c51f3f2b
@@ -516,8 +516,6 @@ The top-level report object has a `results` array containing all linting results
The top-level report object also has `errorCount` and `warningCount` which give the exact number of errors and warnings respectively on all the files.
Report message objects have a deprecated `source` property. This property **will be removed** from the linting messages returned in `messages` in an upcoming breaking release. If you depend on this property, you should now use the top-level `source` or `output` properties instead.
Once you get a report object, it's up to you to determine how to output the results. Fixes will not be automatically applied to the files, even if you set `fix: true` when constructing the `CLIEngine` instance. To apply fixes to the files, call [`outputFixes`](#cliengineoutputfixes).
### CLIEngine#resolveFileGlobPatterns()
@@ -30,17 +30,15 @@ The output of the previous command will be something like this
"message": "Expected { after 'if' condition.",
"line": 2,
"column": 1,
"nodeType": "IfStatement",
"source": "if (err) console.log('failed tests: ' + err);"
"nodeType": "IfStatement"
},
{
"ruleId": "no-process-exit",
"severity": 2,
"message": "Don't use process.exit(); throw an error instead.",
"line": 3,
"column": 1,
"nodeType": "CallExpression",
"source": "process.exit(1);"
"nodeType": "CallExpression"
}
],
"errorCount": 2,
@@ -82,9 +80,6 @@ The following are the fields of the result object:
- **line**: the line where the issue is located.
- **column**: the column where the issue is located.
- **nodeType**: the type of the node in the [AST](https://github.com/estree/estree/blob/master/spec.md#node-objects)
- **source**: an extract of the code the line where the failure happened.
**Please note**: the `source` property will be removed from the message object in an upcoming breaking release. If you depend on this property, you should now use the `source` or `output` properties from [the result object](#the-result-object) instead.
## Examples
@@ -137,8 +132,7 @@ module.exports = function ( results ) {
ruleId: msg.ruleId,
message: msg.message,
line: msg.line,
column: msg.column,
source: msg.source
column: msg.column
};
if ( msg.severity === 1 ) {
@@ -207,8 +201,7 @@ module.exports = function ( results ) {
ruleId: msg.ruleId,
message: msg.message,
line: msg.line,
column: msg.column,
source: msg.source
column: msg.column
};
if ( msg.severity === 1 ) {
View
@@ -138,7 +138,6 @@ function parseJsonConfig(string, location) {
ruleId: null,
fatal: true,
severity: 2,
source: null,
message: `Failed to parse JSON from '${normalizedString}': ${ex.message}`,
line: location.start.line,
column: location.start.column + 1
@@ -319,7 +318,6 @@ function getDirectiveComments(filename, ast, ruleMapper) {
problems.push({
ruleId: name,
severity: 2,
source: null,
message: err.message,
line: comment.loc.start.line,
column: comment.loc.start.column + 1,
@@ -545,7 +543,6 @@ function parse(text, providedParserOptions, parserName, parserMap, filePath) {
ruleId: null,
fatal: true,
severity: 2,
source: null,
message: ex.message,
line: 0,
column: 0
@@ -589,15 +586,13 @@ function parse(text, providedParserOptions, parserName, parserMap, filePath) {
// If the message includes a leading line number, strip it:
const message = `Parsing error: ${ex.message.replace(/^line \d+:/i, "").trim()}`;
const source = ex.lineNumber ? SourceCode.splitLines(text)[ex.lineNumber - 1] : null;
return {
success: false,
error: {
ruleId: null,
fatal: true,
severity: 2,
source,
message,
line: ex.lineNumber,
column: ex.column
View
@@ -201,7 +201,6 @@ function normalizeFixes(descriptor, sourceCode) {
* @param {string} [options.messageId] The error message ID.
* @param {{start: SourceLocation, end: (SourceLocation|null)}} options.loc Start and end location
* @param {{text: string, range: (number[]|null)}} options.fix The fix object
* @param {string[]} options.sourceLines Source lines
* @returns {function(...args): ReportInfo} Function that returns information about the report
*/
function createProblem(options) {
@@ -211,8 +210,7 @@ function createProblem(options) {
message: options.message,
line: options.loc.start.line,
column: options.loc.start.column + 1,
nodeType: options.node && options.node.type || null,
source: options.sourceLines[options.loc.start.line - 1] || ""
nodeType: options.node && options.node.type || null
};
/*
@@ -280,8 +278,7 @@ module.exports = function createReportTranslator(metadata) {
message: normalizeMessagePlaceholders(descriptor),
messageId: descriptor.messageId,
loc: normalizeReportLoc(descriptor),
fix: normalizeFixes(descriptor, metadata.sourceCode),
sourceLines: metadata.sourceCode.lines
fix: normalizeFixes(descriptor, metadata.sourceCode)
});
};
};
@@ -94,7 +94,6 @@ function applyDirectives(options) {
line: directive.unprocessedDirective.line,
column: directive.unprocessedDirective.column,
severity: 2,
source: null,
nodeType: null
}));
View
@@ -355,8 +355,7 @@ describe("CLIEngine", () => {
column: 11,
endLine: 1,
endColumn: 14,
nodeType: "Identifier",
source: "var bar = foo"
nodeType: "Identifier"
}
],
errorCount: 1,
@@ -397,8 +396,7 @@ describe("CLIEngine", () => {
severity: 2,
message: "Parsing error: Unexpected token is",
line: 1,
column: 19,
source: "var bar = foothis is a syntax error."
column: 19
}
],
errorCount: 1,
@@ -439,8 +437,7 @@ describe("CLIEngine", () => {
severity: 2,
message: "Parsing error: Unexpected token",
line: 1,
column: 10,
source: "var bar ="
column: 10
}
],
errorCount: 1,
@@ -527,8 +524,7 @@ describe("CLIEngine", () => {
severity: 2,
message: "Parsing error: Unexpected token is",
line: 1,
column: 19,
source: "var bar = foothis is a syntax error."
column: 19
}
],
errorCount: 1,
@@ -1398,8 +1394,7 @@ describe("CLIEngine", () => {
messageId: "unexpected",
nodeType: "BinaryExpression",
ruleId: "eqeqeq",
severity: 2,
source: "if (msg == \"hi\") {"
severity: 2
}
],
errorCount: 1,
@@ -1419,8 +1414,7 @@ describe("CLIEngine", () => {
message: "'foo' is not defined.",
nodeType: "Identifier",
ruleId: "no-undef",
severity: 2,
source: "var msg = \"hi\" + foo;"
severity: 2
}
],
errorCount: 1,
@@ -3038,7 +3032,6 @@ describe("CLIEngine", () => {
line: 1,
column: 1,
severity: 2,
source: null,
nodeType: null
}
],
@@ -24,8 +24,7 @@ describe("formatter:json", () => {
severity: 2,
line: 5,
column: 10,
ruleId: "foo",
source: "foo"
ruleId: "foo"
}]
}, {
filePath: "bar.js",
@@ -34,8 +33,7 @@ describe("formatter:json", () => {
severity: 1,
line: 6,
column: 11,
ruleId: "bar",
source: "bar"
ruleId: "bar"
}]
}];
View
@@ -1627,7 +1627,6 @@ describe("Linter", () => {
column: 1,
endLine: 1,
endColumn: 25,
source: null,
nodeType: null
}
]
@@ -1646,7 +1645,6 @@ describe("Linter", () => {
column: 1,
endLine: 1,
endColumn: 63,
source: null,
nodeType: null
}
]
@@ -2703,7 +2701,6 @@ describe("Linter", () => {
assert.strictEqual(messages.length, 1);
assert.strictEqual(messages[0].severity, 2);
assert.isNull(messages[0].ruleId);
assert.strictEqual(messages[0].source, BROKEN_TEST_CODE);
assert.strictEqual(messages[0].line, 1);
assert.strictEqual(messages[0].column, 4);
assert.isTrue(messages[0].fatal);
@@ -2721,7 +2718,6 @@ describe("Linter", () => {
assert.strictEqual(messages.length, 1);
assert.strictEqual(messages[0].severity, 2);
assert.strictEqual(messages[0].source, inValidCode[1]);
assert.isTrue(messages[0].fatal);
assert.match(messages[0].message, /^Parsing error:/);
});
@@ -2773,7 +2769,6 @@ describe("Linter", () => {
line: 1,
column: 1,
severity: 1,
source: "var answer = 6 * 7;",
nodeType: null
}
);
@@ -3085,7 +3080,6 @@ describe("Linter", () => {
line: 1,
column: 1,
severity: 2,
source: null,
nodeType: null
}
]
@@ -4228,7 +4222,6 @@ describe("Linter", () => {
assert.strictEqual(messages.length, 1);
assert.strictEqual(messages[0].severity, 2);
assert.isNull(messages[0].source);
assert.strictEqual(messages[0].message, errorPrefix + require(parser).expectedError);
});
Oops, something went wrong.

0 comments on commit 27e3f24

Please sign in to comment.