-
-
Notifications
You must be signed in to change notification settings - Fork 30
New: fixer-return #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
74ec9a1
to
3c96706
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! I left a few comments.
.eslintrc.yml
Outdated
@@ -11,3 +11,6 @@ rules: | |||
self/report-message-format: | |||
- error | |||
- '^[^a-z].*\.$' | |||
node/no-unpublished-require: | |||
- error | |||
- allowModules: ['espree', 'esutils'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we depend on espree and esutils, then I think we should explicitly list them as dependencies, in case eslint
stops depending on them at some point.
lib/ast-utils.js
Outdated
@@ -0,0 +1,1307 @@ | |||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should copy all of ast-utils.js
. That seems like it will be very hard to maintain.
Can utils.getKeyName
be used instead of astUtils.getStaticPropertyName
?
lib/rules/fixer-return.js
Outdated
codePath, | ||
hasReturn: false, | ||
shouldCheck: | ||
node.type === 'FunctionExpression' && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this should check all functions that are named fix
, because some of them might not be related to eslint. It would be better to use getContextIdentifiers
and getReportInfo
to only check fix functions in context.report
calls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need code path analysis here. so I'm using an inelegant way, rather than using getReportInfo.
am I missing something?
@not-an-aardvark sorry about that I'm on a trip, so maybe need a few days to fix this. |
No problem! Enjoy your trip. |
lib/rules/fixer-return.js
Outdated
node.body.type === 'BlockStatement' && | ||
// check if it is context.report({fix}) | ||
utils.getKeyName(parent) === 'fix' && | ||
parent.parent.type === 'ObjectExpression' && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will fail for the old-style context.report
calls:
context.report(node, 'foo', {}, fixer => {});
You can use utils.getReportInfo
to get info about a report.
I think the best way to do it would be to use something like this:
const shouldCheck = node.type === 'FunctionExpression' &&
- node.body.type === 'BlockStatement' &&
- // check if it is context.report({fix})
- utils.getKeyName(parent) === 'fix' &&
parent.parent.type === 'ObjectExpression' &&
parent.parent.parent.type === 'CallExpression' &&
contextIdentifiers.has(parent.parent.parent.callee.object) &&
- parent.parent.parent.callee.property.name === 'report';
+ parent.parent.parent.callee.property.name === 'report' &&
+ utils.getReportInfo(parent.parent.parent.arguments).fix === node;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM aside from a nitpick with the docs. Thanks!
docs/rules/fixer-return.md
Outdated
|
||
## Rule Details | ||
|
||
This rule enforces always return from a fixer function. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: I think it would be better to word this as "This rule enforces that fixer functions always return a value."
fixes #3