Skip to content

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

Merged
merged 8 commits into from
Jul 18, 2017
Merged

Conversation

aladdin-add
Copy link
Contributor

@aladdin-add aladdin-add commented Jul 4, 2017

fixes #3

@aladdin-add aladdin-add force-pushed the issue6 branch 2 times, most recently from 74ec9a1 to 3c96706 Compare July 4, 2017 23:54
@not-an-aardvark not-an-aardvark self-requested a review July 5, 2017 07:18
Copy link
Contributor

@not-an-aardvark not-an-aardvark left a 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']
Copy link
Contributor

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 @@
/**
Copy link
Contributor

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?

codePath,
hasReturn: false,
shouldCheck:
node.type === 'FunctionExpression' &&
Copy link
Contributor

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.

Copy link
Contributor Author

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?

@aladdin-add
Copy link
Contributor Author

@not-an-aardvark sorry about that I'm on a trip, so maybe need a few days to fix this.

@not-an-aardvark
Copy link
Contributor

No problem! Enjoy your trip.

node.body.type === 'BlockStatement' &&
// check if it is context.report({fix})
utils.getKeyName(parent) === 'fix' &&
parent.parent.type === 'ObjectExpression' &&
Copy link
Contributor

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;

@aladdin-add aladdin-add changed the title [WIP] New: fixer-return New: fixer-return Jul 17, 2017
Copy link
Contributor

@not-an-aardvark not-an-aardvark left a 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!


## Rule Details

This rule enforces always return from a fixer function.
Copy link
Contributor

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."

@aladdin-add aladdin-add merged commit 93bd142 into eslint-community:master Jul 18, 2017
@aladdin-add aladdin-add deleted the issue6 branch July 18, 2017 01:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rule: Always return from a fixer function
2 participants