Skip to content
Permalink
Browse files

Update: improve reported location of arrow-parens (fixes #11773) (#11775

)
  • Loading branch information...
g-plane authored and aladdin-add committed May 30, 2019
1 parent d662b17 commit 9590587cef74c936ef9b7ce2d22a71e2fd0fbbc4
Showing with 46 additions and 9 deletions.
  1. +21 −0 lib/rules/arrow-parens.js
  2. +25 −9 tests/lib/rules/arrow-parens.js
@@ -10,6 +10,23 @@

const astUtils = require("./utils/ast-utils");

//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------

/**
* Get location should be reported by AST node.
*
* @param {ASTNode} node AST Node.
* @returns {Location} Location information.
*/
function getLocation(node) {
return {
start: node.params[0].loc.start,
end: node.params[node.params.length - 1].loc.end
};
}

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
@@ -102,6 +119,7 @@ module.exports = {
context.report({
node,
messageId: "unexpectedParensInline",
loc: getLocation(node),
fix: fixParamsWithParenthesis
});
}
@@ -116,6 +134,7 @@ module.exports = {
context.report({
node,
messageId: "expectedParensBlock",
loc: getLocation(node),
fix(fixer) {
return fixer.replaceText(firstTokenOfParam, `(${firstTokenOfParam.value})`);
}
@@ -135,6 +154,7 @@ module.exports = {
context.report({
node,
messageId: "unexpectedParens",
loc: getLocation(node),
fix: fixParamsWithParenthesis
});
}
@@ -149,6 +169,7 @@ module.exports = {
context.report({
node,
messageId: "expectedParens",
loc: getLocation(node),
fix(fixer) {
return fixer.replaceText(firstTokenOfParam, `(${firstTokenOfParam.value})`);
}
@@ -82,6 +82,7 @@ const invalid = [
errors: [{
line: 1,
column: 1,
endColumn: 2,
messageId: "expectedParens",
type
}]
@@ -92,6 +93,7 @@ const invalid = [
errors: [{
line: 1,
column: 1,
endColumn: 2,
messageId: "expectedParens",
type
}]
@@ -102,6 +104,7 @@ const invalid = [
errors: [{
line: 1,
column: 1,
endColumn: 2,
messageId: "expectedParens",
type
}]
@@ -112,6 +115,7 @@ const invalid = [
errors: [{
line: 1,
column: 8,
endColumn: 11,
messageId: "expectedParens",
type
}]
@@ -122,6 +126,7 @@ const invalid = [
errors: [{
line: 1,
column: 8,
endColumn: 11,
messageId: "expectedParens",
type
}]
@@ -132,6 +137,7 @@ const invalid = [
errors: [{
line: 1,
column: 3,
endColumn: 6,
messageId: "expectedParens",
type
}]
@@ -142,7 +148,8 @@ const invalid = [
parserOptions: { ecmaVersion: 8 },
errors: [{
line: 1,
column: 3,
column: 9,
endColumn: 12,
messageId: "expectedParens",
type
}]
@@ -155,7 +162,8 @@ const invalid = [
options: ["as-needed"],
errors: [{
line: 1,
column: 1,
column: 2,
endColumn: 3,
messageId: "unexpectedParens",
type
}]
@@ -167,7 +175,8 @@ const invalid = [
parserOptions: { ecmaVersion: 8 },
errors: [{
line: 1,
column: 1,
column: 2,
endColumn: 3,
messageId: "unexpectedParens",
type
}]
@@ -179,7 +188,8 @@ const invalid = [
parserOptions: { ecmaVersion: 8 },
errors: [{
line: 1,
column: 1,
column: 8,
endColumn: 9,
messageId: "unexpectedParens",
type
}]
@@ -191,7 +201,8 @@ const invalid = [
parserOptions: { ecmaVersion: 8 },
errors: [{
line: 1,
column: 1,
column: 7,
endColumn: 8,
messageId: "unexpectedParens",
type
}]
@@ -205,6 +216,7 @@ const invalid = [
errors: [{
line: 1,
column: 1,
endColumn: 2,
messageId: "expectedParensBlock",
type
}]
@@ -215,7 +227,8 @@ const invalid = [
options: ["as-needed", { requireForBlockBody: true }],
errors: [{
line: 1,
column: 1,
column: 2,
endColumn: 3,
messageId: "unexpectedParensInline",
type
}]
@@ -227,7 +240,8 @@ const invalid = [
parserOptions: { ecmaVersion: 8 },
errors: [{
line: 1,
column: 1,
column: 7,
endColumn: 8,
messageId: "expectedParensBlock",
type
}]
@@ -239,7 +253,8 @@ const invalid = [
parserOptions: { ecmaVersion: 8 },
errors: [{
line: 1,
column: 1,
column: 8,
endColumn: 9,
messageId: "unexpectedParensInline",
type
}]
@@ -251,7 +266,8 @@ const invalid = [
parserOptions: { ecmaVersion: 8 },
errors: [{
line: 1,
column: 1,
column: 7,
endColumn: 8,
messageId: "unexpectedParensInline",
type
}]

0 comments on commit 9590587

Please sign in to comment.
You can’t perform that action at this time.