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

chore(eslint): add unicorn/no-negated-condition rule #2876

Merged
merged 2 commits into from
Sep 22, 2023

Conversation

csouchet
Copy link
Member

@csouchet csouchet commented Sep 20, 2023

To avoid to have to many changes by enabling plugin:unicorn/recommended, I choose to enable some rule one-by-one.

https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-negated-condition.md

Part of #2824 

⚠️  For the code coverage, it was already the case before this PR.

Covers #2742

@csouchet csouchet added chore Build, CI/CD or repository tasks (issues/PR maintenance, environments, ...) depends on another PR ⚠️ Pull request depending on another one. The depending must be merged first refactoring Code refactoring labels Sep 20, 2023
@github-actions
Copy link

github-actions bot commented Sep 20, 2023

♻️ PR Preview e9ca6e7 has been successfully destroyed since this PR has been closed.

🤖 By surge-preview

@github-actions
Copy link

github-actions bot commented Sep 20, 2023

♻️ PR Preview e9ca6e7 has been successfully destroyed since this PR has been closed.

🤖 By surge-preview

@csouchet csouchet force-pushed the 2742-add_unicorn/no-negated-condition_rule branch from 3d01c9d to e9ca6e7 Compare September 22, 2023 08:41
@csouchet csouchet removed the depends on another PR ⚠️ Pull request depending on another one. The depending must be merged first label Sep 22, 2023
@sonarcloud
Copy link

sonarcloud bot commented Sep 22, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

82.1% 82.1% Coverage
0.0% 0.0% Duplication

@csouchet csouchet marked this pull request as ready for review September 22, 2023 08:46
Copy link
Member

@tbouffard tbouffard left a comment

Choose a reason for hiding this comment

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

This rule really improves the readability of the code 👍🏿
✔️ All checks pass
ℹ️ I have notice something that may have long term impact in some cases (mxGraph code modifications)

@@ -30,7 +30,7 @@ export class BpmnCellRenderer extends mxgraph.mxCellRenderer {
dict = new mxgraph.mxDictionary<mxShape>();

for (const currentOverlay of overlays) {
const shape = state.overlays != null ? state.overlays.remove(currentOverlay) : null;
const shape = state.overlays == null ? null : state.overlays.remove(currentOverlay);
Copy link
Member

Choose a reason for hiding this comment

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

question: this is mainly a warning for the next estlint rules we will enabled. The question is: "@csouchet do do you agree with the following statement?"

Here, we modify some original mxGraph code. Up to now, we've tried to modify the code only when necessary. This was initially done to manage mxGraph version changes (know what we've changed, so if the original mxGraph code changes, we can more easily backport our changes to the new implementation).
With mxGraph at the end of its life, this is probably no longer a strong requirement. However, if we decide to switch to maxGraph, it may be useful for the initial migration. The ability to modify maxGraph will be resurrected.

Here, we're starting to change something that isn't necessary, except to match our linting rules (we've done it before, but that was for indentation, or switching to TypeScript, but only very slight things).
The change here doesn't alter the effect of the implementation: it just reverses the condition. So, in this case, I think it's safe to apply the change.
This may not be the case for other types of changes due to the next unicorn rules we may activate.

Copy link
Member Author

Choose a reason for hiding this comment

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

@tbouffard  hadn't paid attention to the changes here, but indeed, for other rules, I disabled them on the mxgraph code, because I didn't know the impact, for example replacing null with undefined.

Comment on lines +137 to 141
if (off == 0) {
this.node.removeAttribute('transform');
} else {
this.node.setAttribute('transform', 'translate(' + off + ',' + off + ')');
}
Copy link
Member

Choose a reason for hiding this comment

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

thought: the change updates the original code of mxGraph. See my remark about src/component/mxgraph/BpmnCellRenderer.ts

@csouchet csouchet merged commit 6174277 into master Sep 22, 2023
27 checks passed
@csouchet csouchet deleted the 2742-add_unicorn/no-negated-condition_rule branch September 22, 2023 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Build, CI/CD or repository tasks (issues/PR maintenance, environments, ...) refactoring Code refactoring
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants