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

CSS lint errors for SCSS stylesheet files (e.g. Unknown word; ...) #731

Closed
4 tasks done
strarsis opened this issue Nov 28, 2021 · 12 comments
Closed
4 tasks done

CSS lint errors for SCSS stylesheet files (e.g. Unknown word; ...) #731

strarsis opened this issue Nov 28, 2021 · 12 comments
Assignees
Labels
bug Something isn't working @roots/bud-sass

Comments

@strarsis
Copy link

strarsis commented Nov 28, 2021

Description

CSS lint errors occur with SCSS styles, e.g.
✖ Unknown word CssSyntaxError
for valid SCSS syntax for variables, single-line comments, etc.

Steps to reproduce

  1. Initialize new Sage 10 theme from dev-master for bud.
  2. Install @roots/bud-sass as development dependency and it to bud.use
    (instructions; minimal example in this repository)
  3. Use SCSS files instead of CSS files
    (e.g. rename the existing app.css and editor.css to app.scss and editor.scss).
  4. Add some SCSS specific syntax that would be invalid in CSS,
    e.g. a SCSS variable ($) or a single line comment (//).
  5. Run the build. Notice the CSS lint errors that normally also prevent the build.

Expected behavior:
bud should configure (webpack) to use a different linter for SCSS files or
let the existing linter correctly handle SCSS files as SCSS files and not CSS files.

Actual behavior:
Linter is configured to treat SCSS files as CSS files, causing lint errors.

Reproduces how often:
Every time.

Versions

``
Node 16.9.1
WSL `2`
Last Sage 10 changelog entry: `Replace Laravel Mix with Bud (#2643)`

@strarsis strarsis changed the title CSS Lint errors for SCSS (Unknown word, ...) CSS lint errors for SCSS (Unknown word, ...) Nov 28, 2021
@strarsis strarsis changed the title CSS lint errors for SCSS (Unknown word, ...) CSS lint errors for SCSS stylesheet files (Unknown word, ...) Nov 28, 2021
@strarsis
Copy link
Author

strarsis commented Nov 28, 2021

Also re-installed @types/sass and @roots/bud-sass as development dependencies,
as in examples package.json.

The issue is still there, the other files build, but no the styles to CSS files.
Scrolling up the build log one can see the linter/build errors.

@strarsis strarsis reopened this Nov 28, 2021
@kellymears kellymears self-assigned this Nov 28, 2021
@kellymears kellymears added @roots/bud-sass bug Something isn't working labels Nov 28, 2021
@kellymears
Copy link
Contributor

kellymears commented Nov 28, 2021

there are two things going on here. both of them are easy fixes for you right now and can be addressed in the repo in the next beta.

user ./.stylelintrc

partially, this is a stylelint config issue. you want to add the following to ./.stylelintrc. you also need to install stylelint-scss.

{
  "plugins": ["stylelint-scss"],
  "customSyntax": "postcss-scss",
  // ...config follows
}

with that rule in place scss syntax compiles for me in @roots/sage.

maybe @roots/bud-sass should check if @roots/bud-postcss and @roots/bud-stylelint are all installed to apply this automatically to the stylelint base config.

or maybe @roots/sage (the bud preset) should do the check. i'm not sure. @benword @QWp6t, thoughts?

@roots/bud-sass bug

there is still a warning thrown and if you use stuff like inline comments it will probably be an error. i'll address this in a PR on @roots/bud-sass today but you can add a pretty small workaround for now and be totally set. you should not need to install postcss-scss -- it is provided by @roots/bud-sass in the current beta.

/**
  * Add postcss-scss syntax
  *
  * @remarks
  * fix for @roots/bud@^5.0.0-next.16. 
  * can be removed in @roots/bud@^5.0.0-next.17.
  *
  * @see {@link https://git.io/JM8ym}
  */
config.tap(bud => {
  const options = bud.build.items.postcss.options(app);
  options.postcssOptions.syntax = 'postcss-scss';
}) 
// ...rest of sage configuration

@strarsis
Copy link
Author

@kellymears: Hm, is there bud API that allows for manipulating the config files like .stylelintrc?
Or changing the file itself? Then the bud SASS extension can automatically do this configuration.

@strarsis strarsis changed the title CSS lint errors for SCSS stylesheet files (Unknown word, ...) CSS lint errors for SCSS stylesheet files (e.g. Unknown word; ...) Nov 29, 2021
@kellymears
Copy link
Contributor

kellymears commented Nov 29, 2021

@strarsis there is a way to override and/or provide base configuration for stylelint.

that's what i meant when i said

maybe @roots/bud-sass should check if @roots/bud-postcss and @roots/bud-stylelint are all installed to apply this automatically to the stylelint base config.

still curious what @retlehs and @QWp6t think. on the one hand i think of stylelint configs as the kind of thing that lives out in userland. but on the other hand it really would be nice to just have this magically work. i can't imagine use cases where someone wants to use stylelint and sass together without this stylelint plugin.

we'd handle it the same way i handled interfacing with postcss in #737

@mensch
Copy link

mensch commented Feb 14, 2022

I believe this is broken again in 5.3.2. I have the following in my .stylelintrc, but the build task still outputs errors related to not recognising the syntax (e.g. Unexpected unknown function "math.floor").

{
  "extends": [
    "@roots/sage/stylelint-config",
    "@roots/bud-sass/stylelint-config"
  ],
  "rules": {
    "no-descending-specificity": null,
    "selector-class-pattern": null
  }
}

devDependencies from package.json:

  "devDependencies": {
    "@roots/bud": "^5.3.2",
    "@roots/bud-eslint": "^5.3.2",
    "@roots/bud-postcss": "^5.3.2",
    "@roots/bud-prettier": "^5.3.2",
    "@roots/bud-sass": "^5.3.2",
    "@roots/bud-stylelint": "^5.3.2",
    "@roots/sage": "^5.3.2",
    "@typescript-eslint/eslint-plugin": "^5.10.2",
    "@typescript-eslint/parser": "^5.10.2",
    "fork-ts-checker-webpack-plugin": "^7.0.0",
    "svg-spritemap-webpack-plugin": "^4.4.0",
    "typescript": "^4.5.5"
  },

@kellymears
Copy link
Contributor

kellymears commented Feb 14, 2022

@mensch can you try changing the order of @roots/sage/stylelint-config and @roots/bud-sass/stylelint-config in your .stylelintrc and report back if it persists?

Additionally, the output of yarn why stylelint-config-recommended. Hopefully it looks something like this:

❯ yarn why stylelint-config-recommended
yarn why v1.22.17
[1/4] 🤔  Why do we have the module "stylelint-config-recommended"...?
[2/4] 🚚  Initialising dependency graph...
[3/4] 🔍  Finding dependency...
[4/4] 🚡  Calculating file sizes...
=> Found "[email protected]"
info Reasons this module exists
   - "@roots#bud-sass#stylelint-config-recommended-scss" depends on it
   - Hoisted from "@roots#bud-sass#stylelint-config-recommended-scss#stylelint-config-recommended"

Your error report makes me think you are on a version prior to 6.0.0. This might be resolved by removing the ^ from your versions:

    "@roots/bud": "5.3.2",
    "@roots/bud-eslint": "5.3.2",
    "@roots/bud-postcss": "5.3.2",
    "@roots/bud-prettier": "5.3.2",
    "@roots/bud-sass": "5.3.2",
    "@roots/bud-stylelint": "5.3.2",
    "@roots/sage": "5.3.2",

which should probably be our default recommendation, regardless.

@mensch
Copy link

mensch commented Feb 14, 2022

Just swapped those out, but no change, unfortunately. Remove either one of the entries, or all of them doesn't make a difference either.

This is the output of yarn why:

│  └─ stylelint-config-recommended@npm:6.0.0 (via npm:^6.0.0)
│
├─ stylelint-config-recommended-scss@npm:5.0.2 [b10d3]
│  └─ stylelint-config-recommended@npm:6.0.0 [2ab46] (via npm:^6.0.0 [2ab46])
│
├─ stylelint-config-standard@npm:25.0.0
│  └─ stylelint-config-recommended@npm:7.0.0 (via npm:^7.0.0)
│
└─ stylelint-config-standard@npm:25.0.0 [4289f]
   └─ stylelint-config-recommended@npm:7.0.0 [be706] (via npm:^7.0.0 [be706])```

@kellymears
Copy link
Contributor

Also, I love godspeed.

@mensch
Copy link

mensch commented Feb 14, 2022

Your error report makes me think you are on a version prior to 6.0.0. This might be resolved by removing the ^ from your versions:

I removed the ^ from the package version and did a clean install, but that doesn't seem to have any effect.

Also, I love godspeed.

Had that avatar for ages. But I think it's from one of their best albums, the more recent stuff doesn't do it for me really.

@kellymears
Copy link
Contributor

stylelint-config-recommended-scss has not been updated to support the latest version of stylelint/stylelint-config-recommended. There was a new rule added which the stylelint-config-recommended-scss preset is unaware of.

add the following rule to your styelint until that config is updated:

    "function-no-unknown": null,

if coming from an older version of sass you will also need to import the math module at the top of your stylesheet. don't know if that applies here:

@use 'sass:math';

@akiletour
Copy link

@kellymears your temporary fix is ok for me :)

@kellymears
Copy link
Contributor

I think the original scope of this issue is pretty fully covered. I'm going to go ahead and close this.

We'll roll out a point release as soon as stylelint-config-recommended-scss is updated. Until then disabling the function-no-unknown rule should fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working @roots/bud-sass
Projects
None yet
Development

No branches or pull requests

4 participants