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

Migrate stylelint to latest version #2292 #2425

Merged
merged 12 commits into from Feb 29, 2024

Conversation

LamJiuFong
Copy link
Contributor

@LamJiuFong LamJiuFong commented Feb 15, 2024

What is the purpose of this pull request?
Fixes #2292

  • Documentation update
  • Bug fix
  • Feature addition or enhancement
  • Code maintenance
  • DevOps
  • Improve developer experience
  • Others, please explain:

Overview of changes:
Migrate stylelint to latest version ^16.0.0
Add devdependency "stylelint-config-recommended-vue"
Add plugin @stylistic/stylelint-plugin
Add dependency postcss@^8.4.35
Fix syntax to obey new rules

Anything you'd like to highlight/discuss:
Added a comment below

Testing instructions:

Proposed commit message: (wrap lines at 72 characters)
Migrate stylelint to v16.0.0


Checklist: ☑️

  • Updated the documentation for feature additions and enhancements
  • Added tests for bug fixes or features
  • Linked all related issues
  • No unrelated changes

Reviewer checklist:

Indicate the SEMVER impact of the PR:

  • Major (when you make incompatible API changes)
  • Minor (when you add functionality in a backward compatible manner)
  • Patch (when you make backward compatible bug fixes)

At the end of the review, please label the PR with the appropriate label: r.Major, r.Minor, r.Patch.

Breaking change release note preparation (if applicable):

  • To be included in the release note for any feature that is made obsolete/breaking

Give a brief explanation note about:

  • what was the old feature that was made obsolete
  • any replacement feature (if any), and
  • how the author should modify his website to migrate from the old feature to the replacement feature (if possible).

Jiu Fong Lam added 2 commits February 15, 2024 23:43
Add dependency "stylelint-config-recommended-vue"
Fix syntax to obey new rules
@LamJiuFong
Copy link
Contributor Author

Hi, I am currently working on this issue locally and I would like to ask for some advices:

This is what I've done:

  1. Update the dependencies to the latest versions and add the dependency stylelint-config-recommended-vue since stylelint doesn't support linting vue files and it is also a recommended config by stylelint.Screenshot 2024-02-15 at 2 35 19 PM

  2. Add stylelint-config-recommended-vue to the extension list and removed (commented out) the indentation rule since it is not supported by stylelint. Screenshot 2024-02-15 at 2 39 30 PM

  3. Run npm install followed by npm run csslintfix and got the errors below:

Screenshot 2024-02-15 at 2 42 14 PM
  1. Manually fix the errors above, no errors left.
  2. Run npm run updatetest and npm run test. Successfully ran target test.

My questions are:

  1. Is it the right way to solve this issue by following the steps above? Did I miss out anything?
  2. Do I need to change anything in the .github/workflows/ci.yml file? If not, is it because Github Actions will run the ci.yml in my code which uses the updated dependencies.
  3. Some new rules are introduced and running npm run csslintfix changes the original code.
    eg. border-color: rgba(150, 150, 150, 0.2) is changed to border-color: rgb(150 150 150 / 20%). Is it okay to keep the new changes? I think it should be fine as long as the syntax is standardised everywhere.
  4. Not sure why some css files are included in .stylelintignore, could someone explain the purpose of it? Thanks!
Screenshot 2024-02-15 at 8 54 18 PM

@EltonGohJH
Copy link
Contributor

  1. Is it the right way to solve this issue by following the steps above? Did I miss out anything?

Looks correct on my end. For the indentation rule can you check on whether we can get a replacement?

  1. Do I need to change anything in the .github/workflows/ci.yml file? If not, is it because Github Actions will run the ci.yml in my code which uses the updated dependencies.

I dun think so? We still run npm run test command in CI? (There is no change right?) If any change, you should change our test command.

  1. Some new rules are introduced and running npm run csslintfix changes the original code.
    eg. border-color: rgba(150, 150, 150, 0.2) is changed to border-color: rgb(150 150 150 / 20%). Is it okay o keep the new changes? I think it should be fine as long as the syntax is standardised everywhere.

I agree that if you can fix and ensure that this new style is standardised in current code base then it is good to go.

  1. Not sure why some css files are included in .stylelintignore, could someone explain the purpose of it? Thanks!
  1. min.css is ignored because it is minified and will not follow the standards
  2. _site is the css in templates and should not be linted.
  3. coverage and test should not be linted
  4. Vue components folder also has coverage folder. Maybe you can specify just the coverage folder? I dun think our vue components folder has css files. (Double check)

Copy link

codecov bot commented Feb 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 48.92%. Comparing base (990d613) to head (f9ba940).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2425   +/-   ##
=======================================
  Coverage   48.92%   48.92%           
=======================================
  Files         124      124           
  Lines        5245     5245           
  Branches     1110     1110           
=======================================
  Hits         2566     2566           
  Misses       2371     2371           
  Partials      308      308           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@LamJiuFong
Copy link
Contributor Author

Looks correct on my end. For the indentation rule can you check on whether we can get a replacement?

I have added a plugin @stylistic/stylelint-plugin to solve this issue as they support the deprecated indentation rule.

I dun think so? We still run npm run test command in CI? (There is no change right?) If any change, you should change our test command.

Yup, there is no change

I agree that if you can fix and ensure that this new style is standardised in current code base then it is good to go.

Ok

  1. Vue components folder also has coverage folder. Maybe you can specify just the coverage folder? I dun think our vue components folder has css files. (Double check)

Yes, I checked and there is no css files in the vue-components folder.

Something to add on:

I ran to this error when running npm run csslint:

SyntaxError: Named export 'Input' not found. The requested module 'postcss' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'postcss';
const { rule: _rule, Input } = pkg;

This is because @stylistic/stylelint-plugin uses named export for Input and postcss only supports this starting from v8,
Screenshot 2024-02-25 at 7 42 07 PM

So, I added a dependency to specify the version of postcss to ^8.4.35 to get over this issue.

@@ -27,8 +27,7 @@ pre.hljs > code {
background: none;
}

pre > code.hljs {
Copy link
Contributor

Choose a reason for hiding this comment

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

Most of these lint changes look like lint changes -> but this one confuses me, because it seems to just remove the -webkit-background-clip ? Any idea of the reason for this?

Copy link
Contributor

Choose a reason for hiding this comment

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

...Answered my own question: here are the links to read about it:

Stylelint removes vendor prefixes

this is a danger for specific properties... eg background-clip: text ... but this particular case doesn't seem to be an issue

Background reading on vendor prefixing: Is vendor prefixing dead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, it violates the property-no-vendor-prefix rule.
Screenshot 2024-02-25 at 8 15 11 PM

We can solve this issue by ignoring the property.
Screenshot 2024-02-25 at 8 28 32 PM

This will keep the original line
-webkit-background-clip: padding-box; /* for Safari */

I think we can do this, what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

The understanding I have is that when this code was written, the browsers required prefixing for these due to not supporting the properties unprefixed. Stylelint relies on autoprefixer, an open source project that automatically adds prefixes when needed.

The implication here is that the prefixes are no longer needed due to them being supported by the browser at this point, though they were not supported in the past.

Hence, assuming there is no change in behaviour, I think we should keep the rule and change the CSS.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh! However do remove the comments "for safari" / references to other browsers, as these are no longer relevant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I think you are right, for now since browsers do not require vendor prefixes, I think the line background-clip: padding-box would be enough to accommodate all browsers.

I have removed the unnecessary comments.

Copy link
Contributor

@kaixin-hc kaixin-hc left a comment

Choose a reason for hiding this comment

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

LGTM - I don't love how many changes there are, but I suppose it is somewhat expected with a linting tool. Will wait before merging in case I've missed something.

@kaixin-hc kaixin-hc changed the title [Request for Early Review] Migrate stylelint to latest version #2292 Migrate stylelint to latest version #2292 Feb 25, 2024
@kaixin-hc
Copy link
Contributor

Would you also add "Fixes #2292" to the PR description? This allows us to auto-close the issue and links the issue in the body so it easier for the reviewers!

@LamJiuFong
Copy link
Contributor Author

Added!

Copy link
Contributor

@yucheng11122017 yucheng11122017 left a comment

Choose a reason for hiding this comment

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

Hi @LamJiuFong thank you very much for the good work!
One minor nit and one issue with the tooltip styling

package.json Outdated Show resolved Hide resolved
@@ -71,9 +71,9 @@ export default {
</script>

<style>
.v-popper--theme-tooltip .v-popper__inner {
.v-popper-theme-tooltip .v-popper-inner {
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems to be having unexpected effects - the styling doesn't apply to the tooltip anymore.
You can try modifying the font size to something huge and then removing the one of the dashes, you realise the font change doesn't apply.
Can we keep the old version? Will it automatically change every time the linter is run?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Screenshot 2024-02-28 at 9 19 24 PM

The namings here violated the rule selector-class-pattern.
To revert it back to the old version and prevent stylelint from throwing an error, I have added a line comment on top of it to disable stylelint for this part. (this is how stylelint is disabled for a particular part of code)

Copy link
Contributor

@yucheng11122017 yucheng11122017 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 the work @LamJiuFong :)

@kaixin-hc kaixin-hc merged commit 9336559 into MarkBind:master Feb 29, 2024
9 checks passed
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.

Migrate stylelint to latest for security updates
4 participants