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

feat: no-depends-on-boolean-flag rule #447

Merged
merged 17 commits into from
Jul 26, 2024
Merged

Conversation

cristiand391
Copy link
Member

@cristiand391 cristiand391 commented Jul 25, 2024

Closes: #446

Adds a new no-depends-on-boolean-flag rule, see: https://github.com/salesforcecli/eslint-plugin-sf-plugin/blob/cd/depend-on-boolean-flag/docs/rules/no-depends-on-boolean-flag.md

Didn't do the autofix because I'm not sure it would be a good default and added more complexity (had to handle flags with relationships already defined, what if you really wanted it to depend on value, etc).

@W-16320656@

@cristiand391 cristiand391 changed the title feat: no-depends-on-boolean-flag rule feat: no-depends-on-boolean-flag rule Jul 25, 2024
@cristiand391 cristiand391 marked this pull request as ready for review July 25, 2024 19:18
@@ -10,6 +10,8 @@ jobs:
linux-unit-tests:
needs: yarn-lockfile-check
uses: salesforcecli/github-workflows/.github/workflows/unitTestsLinux.yml@main
with:
skipTsDepCheck: true
Copy link
Member Author

Choose a reason for hiding this comment

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

opt-in way to disable the ts-dep-check, see: salesforcecli/github-workflows#120

this is a devDep so it's ok to ship TS

@@ -90,6 +91,7 @@ const recommended = {
'sf-plugin/no-default-and-depends-on-flags': 'error',
'sf-plugin/only-extend-SfCommand': 'warn',
'sf-plugin/spread-base-flags': 'warn',
'sf-plugin/no-depends-on-boolean-flag': 'warn',
Copy link
Member Author

Choose a reason for hiding this comment

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

warn instead of error because there are cases where depending on a boolean flag works as expected:

  • flag1 is boolean and has no default value/no allowNo
  • flag2 depends on flag1

there's no way flag1 can have a value if it's not passed in. Still, the warning should push users to double-check and future-proof their code 😉

f.value.callee.type == AST_NODE_TYPES.MemberExpression &&
f.value.callee.property.type == AST_NODE_TYPES.Identifier &&
f.value.callee.property.name === 'boolean'
);
Copy link
Member Author

Choose a reason for hiding this comment

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

recommended: 'recommended',
},
messages: {
message: 'Cannot create a flag that `dependsOn` a boolean flag',
Copy link
Contributor

@mshanemc mshanemc Jul 25, 2024

Choose a reason for hiding this comment

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

can the message say more, something like, "use the relationships property with a when function".

mshanemc and others added 3 commits July 26, 2024 09:56
* refactor: pr review

* refactor: min/max/default
@cristiand391
Copy link
Member Author

@mshanemc this PR has a ton of commits, make sure to squash-merge it when QA is done.

@mshanemc mshanemc merged commit bb0f816 into main Jul 26, 2024
45 checks passed
@mshanemc mshanemc deleted the cd/depend-on-boolean-flag branch July 26, 2024 13:56
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.

add rule to catch flags depending on boolean flags
2 participants