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(lint): add Airbnb and Unicorn eslint packages #2596

Merged
merged 2 commits into from
Dec 11, 2022

Conversation

mvorisek
Copy link
Contributor

@mvorisek mvorisek commented Dec 11, 2022

Add eslint plugin packages with recommended rules to be fixed in separate PRs.

@mvorisek mvorisek marked this pull request as ready for review December 11, 2022 16:41
@mvorisek
Copy link
Contributor Author

This PR (part 1 of #2589) is complete.

@@ -27,7 +28,8 @@ var

module.exports = function () {
// use a different config
config = configSetup.addDerivedValues(config);
const config = extend(true, {}, configDocs);
Copy link
Member

Choose a reason for hiding this comment

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

This is still a confusing change. Please revert. addDerivedValues returns config and config is declared via let, so what's the purpose of creating a temporary const which extends the previous config.... This is confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

addDerivedValues() was written quite complited. When no/empty config was given, it created it. Why? When such fallback is removed, no need for return.

By the function name I would expect a void method that adds some config values. This is how it is coded now, is that ok?

The change also fixes the mutation of a config returned from an imported module, previously, it was not extended/cloned. IMHO it is a good practise to never mutate anything imported.

Copy link
Member

Choose a reason for hiding this comment

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

It is still confusing: Why is configDocs now declared outiside of the exports scope? For nothing else than being extended for the const once.... Why not move the let config = require('../config/docs'), into the module.exports block and keep the functionality as it was before?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because it is a good practise to keep imports at the top (and never mutate them) - otherwise eslint with recommended config will warn - otherwise we will need eslint-disable-line

Copy link
Member

@lubber-de lubber-de Dec 11, 2022

Choose a reason for hiding this comment

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

ok, understood, but then it should be kept as var instead of let if we get into scope issues otherwise ;)
[Edit]"and never mutated them" -> yes, right, so this case really needs a refactoring, but lets do it clean instead of the const fix ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If imported on top (with var/let/const), then it is visible to the whole script scope.

Copy link
Member

Choose a reason for hiding this comment

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

Then i am still/again confused again why you renamed that into configDocs and did the additional const stuff in module.exports? Because of the undesired mutation? As said this needs a better refactoring. Maybe we are talking too much about a code which is not even used many times (its about serving docs)

Lets get this PR to some point where we can merge it, as said, i would have already merged lots of other rules if they werent bound altogether in combined PRs 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

now part of #2597

see 117dc67, we import the config as configDocs, then create (local/cloned) config config.

@lubber-de
Copy link
Member

lubber-de commented Dec 11, 2022

@mvorisek

Don't get me wrong, i highly appreciate what you are doing here 👍🏼 But you are preparing lots of similiar PRs always containing several rules and if only one of them turns into discussion we never get close into getting most of them included :)

I actually dont want to rewrite ancient (but working) code just because airbnb rules now tell us we should code different.
linting rules are still opinion based. 😉

That said, i am totally fine with many other rules which do not need code structure changes , but please keep the whole var/let/const changes in a separate PR which does nothing else. Thanks.

I am fine with a lot of PRs having a single lint rule. This makes approvement/review much easier and we can concentrate on one topic and merging gets faster as we won't loose time (or me investigating what code, i never touched before, is doing and why the linter thinks it has to be changed).

You are doing a great job these days, thanks a lot! 🙂

@mvorisek mvorisek force-pushed the airbnb_part1 branch 2 times, most recently from c781915 to e359b44 Compare December 11, 2022 20:30
@mvorisek
Copy link
Contributor Author

But you are preparing lots of similiar PRs always containing several rules

I have a "master" PR #2589 which I split and split :)

The older PRs are to be merged later, they hold changes not compatible with Node 12/ (and E11).

Thankfully, I made the changes quite strictly rule by rule so I can reduce the PR size easily.

This PR now adds the linter packages only.

@mvorisek mvorisek changed the title Add Airbnb and Unicorn linters Add Airbnb and Unicorn linter packages Dec 11, 2022
@mvorisek mvorisek changed the title Add Airbnb and Unicorn linter packages Add Airbnb and Unicorn eslint packages Dec 11, 2022
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 :)

@lubber-de lubber-de changed the title Add Airbnb and Unicorn eslint packages feat(lint): add Airbnb and Unicorn eslint packages Dec 11, 2022
@lubber-de lubber-de merged commit aa53fbd into fomantic:develop Dec 11, 2022
@lubber-de lubber-de added type/feat Any feature requests or improvements type/ci Anything related to CI/CD javascript Pull requests that update Javascript code lang/javascript Anything involving JavaScript and removed javascript Pull requests that update Javascript code labels Dec 11, 2022
@lubber-de lubber-de added this to the 2.9.1 milestone Dec 11, 2022
@mvorisek mvorisek deleted the airbnb_part1 branch December 11, 2022 21:26
@lubber-de
Copy link
Member

@mvorisek
mmh, my local eslint throws an error now after merge..i wonder why the ci didnt?

Error: Failed to load config "airbnb-base" to extend from.
Referenced from: C:\gitrepos\Fomantic-UI\.eslintrc.js

Error: Failed to load config "airbnb-base" to extend from.
Referenced from: C:\gitrepos\Fomantic-UI\.eslintrc.js
    at configInvalidError (C:\gitrepos\Fomantic-UI\node_modules\@eslint\eslintrc\dist\eslintrc.cjs:2627:9)
    at ConfigArrayFactory._loadExtendedShareableConfig (C:\gitrepos\Fomantic-UI\node_modules\@eslint\eslintrc\dist\eslintrc.cjs:3258:23)
    at ConfigArrayFactory._loadExtends (C:\gitrepos\Fomantic-UI\node_modules\@eslint\eslintrc\dist\eslintrc.cjs:3135:25)
    at ConfigArrayFactory._normalizeObjectConfigDataBody (C:\gitrepos\Fomantic-UI\node_modules\@eslint\eslintrc\dist\eslintrc.cjs:3074:25)
    at _normalizeObjectConfigDataBody.next (<anonymous>)
    at ConfigArrayFactory._normalizeObjectConfigData (C:\gitrepos\Fomantic-UI\node_modules\@eslint\eslintrc\dist\eslintrc.cjs:3019:20)
    at _normalizeObjectConfigData.next (<anonymous>)
    at ConfigArrayFactory.loadInDirectory (C:\gitrepos\Fomantic-UI\node_modules\@eslint\eslintrc\dist\eslintrc.cjs:2865:28)
    at CascadingConfigArrayFactory._loadConfigInAncestors (C:\gitrepos\Fomantic-UI\node_modules\@eslint\eslintrc\dist\eslintrc.cjs:3848:46)
    at CascadingConfigArrayFactory.getConfigArrayForFile (C:\gitrepos\Fomantic-UI\node_modules\@eslint\eslintrc\dist\eslintrc.cjs:3769:18)

@lubber-de
Copy link
Member

nevermind.... found the issue 😉

@lubber-de
Copy link
Member

lubber-de commented Dec 11, 2022

@mvorisek Another "issue".
Since the last merge my jetbrains IDE eslint moans about me using windows.

Expected linebreaks to be 'LF' but found 'CRLF'

If this is a default rule in airbnb-ruleset, how can we override that? linebreak-style is not set inside our own eslintrc.

my git config is configured to use LF only when pushing but CRLF when checking out on windows (standard git setting under windows "core.autolcrlf=true"). Of course i dont want to see every code line now being an error, so we should override that rule. Not everybody is using a mac or linux for web development :)

@lubber-de
Copy link
Member

lubber-de commented Dec 11, 2022

This seems to be a reliable override ?

rules: {
        'linebreak-style': ['error', process.platform === 'win32' ? 'windows' : 'unix'],
 }

@lubber-de
Copy link
Member

lubber-de commented Dec 11, 2022

If possible and you are in doubt, somebody could accidently push CRLF: Could we restrict the rule to LF inside CI only?

@mvorisek
Copy link
Contributor Author

mvorisek commented Dec 11, 2022

LF must be used in all source text files

if there is any text file stored as CRLF, please fix

if you have LF locally, I advise to reconfigure your IDE to LF which is used by 99% projects across many programming languages

if you have locally CRLF, it might come from git autocrlf, disable it, I would not advise to let git transform your text files locally, otheriwse you will hit many problems like eslint wanting LF :)

and I will take care of enforcing LF for JS and LESS as well

lubber-de pushed a commit that referenced this pull request Dec 12, 2022
Modernize code using eslint advisory introduced in GH-2596. This PR focuses on fixing no-var rule.

For src/* files it cannot be fixed (now) because of limited support in IE11.
lubber-de pushed a commit that referenced this pull request Dec 12, 2022
Modernize code using eslint advisory introduced in GH-2596. This PR focuses on fixing multiple rare rules, done in one PR, as otherwise there will be only a few LOC changed per separate PR.
lubber-de pushed a commit that referenced this pull request Dec 12, 2022
Modernize code using eslint advisory introduced in GH-2596. This PR focuses on fixing unicorn/no-typeof-undefined rule with some related changes done manually
@lubber-de lubber-de added the type/lint eslint / stylelint related changes only label Dec 12, 2022
lubber-de pushed a commit that referenced this pull request Dec 12, 2022
Modernize code using eslint advisory introduced in GH-2596. This PR focuses on unified regex and .length check usage, also removes useless escapes.
lubber-de pushed a commit that referenced this pull request Dec 12, 2022
Modernize code using eslint advisory introduced in GH-2596. This PR focuses on fixing unicorn/prefer-date-now rule.
lubber-de pushed a commit that referenced this pull request Dec 12, 2022
Modernize code using eslint advisory introduced in GH-2596. This PR focuses on fixing rules like no-else-return and other ternary operator related.
lubber-de pushed a commit that referenced this pull request Dec 12, 2022
Modernize code using eslint advisory introduced in GH-2596. This PR fixes several smaller rules not worth a separate PRs.
lubber-de pushed a commit that referenced this pull request Dec 13, 2022
Modernize code using eslint advisory introduced in GH-2596. This PR updates ternary operator formatting for better readability and and removes unneeded parentheses around expressions.
lubber-de pushed a commit that referenced this pull request Dec 13, 2022
Modernize code using eslint advisory introduced in GH-2596. This PR focuses on fixing no-extra-parens rule with a help or a custom rule output filter.
lubber-de pushed a commit that referenced this pull request Dec 20, 2022
Modernize code using eslint advisory introduced in GH-2596. This PR focuses on fixing no-shadow-restricted-names rule.

Discussed in #2589 (comment), it fixes the rule cleanly and the impact on the total JS size is minimal (<1%).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lang/javascript Anything involving JavaScript type/ci Anything related to CI/CD type/feat Any feature requests or improvements type/lint eslint / stylelint related changes only
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants