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(chore): add lint using CI #2501

Merged
merged 39 commits into from
Dec 4, 2022
Merged

feat(chore): add lint using CI #2501

merged 39 commits into from
Dec 4, 2022

Conversation

mvorisek
Copy link
Contributor

@mvorisek mvorisek commented Oct 15, 2022

Description

Unified CS improves readability, prevents hidden mistakes and enforce unified contribution standards. And in a long term, it also simplifies merge conflicts.

The CS rules are based on industry standard eslint-config-airbnb-base, but all rules might be too hard to fix at once. This PR focuses on whitespace CS which can be autofixed /wo having to review each line manually.

related #29

nicely integrated with Github Actions like:

image

@prudho
Copy link
Contributor

prudho commented Oct 17, 2022

Yes, code linting is definitely something we need to implement. I started using myself eslint at work and this is something i don't regret at all. But... 😅

We cannot implement it, and already use it to enforce merge requests. I think that first we need to define which rules we want to use and the level of error it'll raise. Then we can do some merge requests to fix the code. But we can't fix all the code in one PR, maybe a PR per component.

Once this is done, then we can enforce lint check trough the CI pipeline.

@mvorisek mvorisek force-pushed the lint branch 2 times, most recently from dc1171e to 344266f Compare November 30, 2022 21:23
@mvorisek mvorisek marked this pull request as ready for review November 30, 2022 21:23
@mvorisek
Copy link
Contributor Author

I have updated the PR, instead of using airbnb-base as a base eslint config (with possible side effects) I added the most important whitespaces rules only to match general coding standards. With whitespace changes the code behaviour is not changes and this PR is safe to merge.

In another PR, more eslint rules can be added.

Also don't worry about merge conflicts (from changes based on code before this PR), they can be easily resolved, just cherry pick the eslint rules and run npm run lint-fix, you can then integrate the changes as usual.

Copy link
Member

@lubber-de lubber-de left a comment

Choose a reason for hiding this comment

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

As the PR is basically ok now, i just comment instead of requesting changes as i would like to hear opinion of other maintainers. See my comments below

@mvorisek mvorisek force-pushed the lint branch 2 times, most recently from bc011e3 to 9074205 Compare December 2, 2022 10:34
@lubber-de
Copy link
Member

lubber-de commented Dec 2, 2022

I took a look at the complete files to get myself convinced about the 4 indent 😉 and i recognized the linter does sometimes not implement the 4 indent correctly, which needs (manual?) adjustments, otherwise the new indent is making it worse than before at those codelines, because it gets confusing

For example dimmer.js, look at the semicolon, which terminates the var statement

It is now looking like that
image

while it was and is supposed to look like that (same indent as the var statement)
image

@mvorisek
Copy link
Contributor Author

mvorisek commented Dec 2, 2022

Maybe we need another eslint rule for semicolon, I will have a look on a solution for it.

@mvorisek
Copy link
Contributor Author

mvorisek commented Dec 2, 2022

The solution is to run eslint semi: ['error', 'never'] once and then again. There is no explicit config of indentation for semicolon in eslint.

Multiline expr. is indented correctly, thus IMHO it is better to have the semicolon on the same/last expr line, as the 2nd (and following) multiline expressions are indented visually already.

related issue: eslint/eslint#15752 (the solution with semi: ['error', 'never'] fixes it too)

@lubber-de
Copy link
Member

Well, when adding the semicolon to the end of the last line, why the indention at all then (in such cases)?

image

Also, you added the rule to add a trailing comma in object literals. The linter idea behind that is to easily exchange/adding/removing single lines without the need to also add another comma to the previous attribute notation.
This is the same for such use cases where the semicolon has its own line.

So: Adding the trailing comma but also adding a semicolon to the last entry is not consistent anymore (IMHO even worse)
I would really prefer to have the semicolon being indented as it was before. This clearly shows where the indentation block ends as it is now.

Now we have the discussion i basically want to avoid ;) And now imagine new contributors trying to help and we are going to argue about "correct" whitespacing :)

Don't get me wrong, I am not against the linting. But indentin the semicolons would be the cleaner approach. Yes, this possibly needs a (onetime) manual adjustment if there is no 100% automatic solution.

@mvorisek
Copy link
Contributor Author

mvorisek commented Dec 2, 2022

Well, when adding the semicolon to the end of the last line, why the indention at all then (in such cases)?

chained method call indentation is defacto standard (at least has always been in all codebase I have worked with) and it makes sense, as

$module
    .callOne()
    .callTwo();
$module.callOne();

is IMHO visually more readable and more compact than

$module
.callOne()
.callTwo()
;
$module.callOne();

Don't get me wrong, I am not against the linting. But indentin the semicolons would be the cleaner approach. Yes, this possibly needs a (onetime) manual adjustment if there is no 100% automatic solution.

You are right here, I have reviewed the changes and there are at least two usecases with semicolon on a NL:

a) ternary:

image

I have never seen semicolon on NL for them, also no reason for easier diffing, as ternary operator is always binary.

b) var declaration:

image

I will fix these manually 👍

@exoego
Copy link
Contributor

exoego commented Dec 2, 2022

For the record, I am positive on introducing linter.
I believe it helps both contributors and maintainers.
I defer to lubber on styling preference since he is the most active maintainer.

@lubber-de
Copy link
Member

$module
    .callOne()
    .callTwo();
$module.callOne();

is IMHO visually more readable and more compact than

$module
.callOne()
.callTwo()
;
$module.callOne();

My point basically was about comparison to the trailing comma rule.
If you want to add a .callThree() you now have to remove the semicolon from .callTwo() as well

I will fix these manually 👍

Thx 😊

@mvorisek mvorisek marked this pull request as draft December 3, 2022 00:18
((?:var|const|let)\n[^;]+^( +)    [^;\n]+);\n +
regex: ;\n +\n + eslint fix /w review
 (-|\+|%|/|\*|\|\||&&)(?<!( |\n) \*)$
@mvorisek mvorisek marked this pull request as ready for review December 3, 2022 16:38
@auto-assign auto-assign bot requested a review from lubber-de December 3, 2022 16:38
@mvorisek
Copy link
Contributor Author

mvorisek commented Dec 3, 2022

PR is done, I added more whitespaces rules to match AirBnB CS (basically the rules are copied from their ruleset). The hash of minified semantic.min.js file before and after this PR is unchanged, ie. there is no functional change.

Later, I plan to create another PR which will fix var -> let etc., which can have side effects.

Copy link
Member

@lubber-de lubber-de left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for doing this and your patience 😉

@lubber-de lubber-de changed the title Unify whitespace CS and add lint using CI feat(chore): add lint using CI Dec 4, 2022
@lubber-de lubber-de merged commit 8a8d841 into fomantic:develop Dec 4, 2022
@mvorisek mvorisek deleted the lint branch December 4, 2022 20:08
@lubber-de lubber-de added type/chore Anything which is a project chore type/ci Anything related to CI/CD javascript Pull requests that update Javascript code labels Dec 4, 2022
@lubber-de lubber-de added this to the 2.9.1 milestone Dec 4, 2022
lubber-de pushed a commit that referenced this pull request Dec 9, 2022
Like #2501, but for LESS. No functionality change.
@lubber-de lubber-de added the type/lint eslint / stylelint related changes only label Dec 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
javascript Pull requests that update Javascript code type/chore Anything which is a project chore type/ci Anything related to CI/CD type/lint eslint / stylelint related changes only
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants