Skip to content
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

Fix: no-boolean-default with 'default-false' on boolean props with unset default #821

Merged
merged 1 commit into from
Feb 18, 2019

Conversation

ghost
Copy link

@ghost ghost commented Feb 16, 2019

Currently the rule no-boolean-default breaks when used with option 'default-false' on a boolean prop that does not have default property, with exception:

TypeError: Cannot read property 'value' of undefined
      at booleanProps.forEach.propDef (lib/rules/no-boolean-default.js:7:2342)
      at Array.forEach (<anonymous>)
      at utils.executeOnVueComponent.obj (lib/rules/no-boolean-default.js:7:1808)
      at ExportDefaultDeclaration:exit (lib/utils/index.js:174:251)
      at listeners.(anonymous function).forEach.listener (node_modules/eslint/lib/util/safe-emitter.js:45:58)
      at Array.forEach (<anonymous>)
      at Object.emit (node_modules/eslint/lib/util/safe-emitter.js:45:38)
      at NodeEventGenerator.applySelector (node_modules/eslint/lib/util/node-event-generator.js:251:26)
      at NodeEventGenerator.applySelectors (node_modules/eslint/lib/util/node-event-generator.js:280:22)
      at NodeEventGenerator.leaveNode (node_modules/eslint/lib/util/node-event-generator.js:303:14)
      at CodePathAnalyzer.leaveNode (node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:654:23)
      at nodeQueue.forEach.traversalInfo (node_modules/eslint/lib/linter.js:752:28)
      at Array.forEach (<anonymous>)
      at runRules (node_modules/eslint/lib/linter.js:746:15)
      at Linter._verifyWithoutProcessors (node_modules/eslint/lib/linter.js:891:31)
      at preprocess.map.textBlock (node_modules/eslint/lib/linter.js:940:35)
      at Array.map (<anonymous>)
      at Linter.verify (node_modules/eslint/lib/linter.js:939:42)
      at runRuleForItem (node_modules/eslint/lib/testers/rule-tester.js:385:34)
      at testValidTemplate (node_modules/eslint/lib/testers/rule-tester.js:412:28)
      at Context.RuleTester.it (node_modules/eslint/lib/testers/rule-tester.js:584:25)

This PR adds tests that expose the issue (simply the same cases but applied without options and with each option where applicable) and a check for a falsy value returned from getDefaultNode(propDef).

Also, changed the error message for 'default-false' option a bit, as "Boolean prop should be defaulted to false." may mean that it "should be defaulted", while the logic is "can be defaulted or not, but if it is, it must only be false".

Copy link
Member

@mysticatea mysticatea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you so much!

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.

2 participants