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
Add overrides property to configuration object #3128
Comments
I need this feature too. I have different roles for CSS and CSS-in-JS files. I like |
Can we use different config files in different folders? |
@Grawl not in my case. I have many folders at root. As result, right now I must copy same config to 3-5 places. And it force mistakes — change config in one folder and forget about other folders. |
Appreciate. But we don't have |
Overrides is a good idea. As a temporary solution you can use config
module.exports = {
extends: './.stylelintrc.js',
rules: {
'block-closing-brace-empty-line-before': null,
},
}; It will require two npm tasks to run it, though: stylelint "**/*.css"
stylelint "**/*.sass" --config .stylelintrc.sass.js Or it can be combined into one: stylelint "**/*.css" && stylelint "**/*.sass" --config .stylelintrc.sass.js |
nice workaround! |
It sounds like an |
https://eslint.org/docs/user-guide/configuring#configuration-based-on-glob-patterns |
This is a great idea, but the proposed implementation needs improved: {
"rules": {
"optionOne": true,
"optionTwo": false
},
"overrides": {
"syntax": "sass",
"rules": {
"optionOne": false,
"optionTwo": true
}
}
} What if you have more than just one syntax you want to specify unique rules for? For example if you are linting documentation with markdown examples in multiple meta-languages, or converting a codebase over from Less to Sass. A better implementation could handle this situation by specifying the file extension for the overrides to apply to. This makes the stuff outside of the {
"rules": {
"optionOne": true,
"optionTwo": false
},
"overrides": {
".sass": {
"rules": {
"optionOne": false,
"optionTwo": true
}
},
".less": {},
".styl": {},
".scss": {},
".sss": {},
".css": {}
}
} I understand that stylelint may be linting a syntax in a markdown file or something else, and not a literal Alternatively, there could be logic to handle multiple strings referencing the same syntax, if you wanted to make the API more loose so people could name them any version of the syntax/meta-language name. if (stylelintrc.styl || stylelintrc['.styl'] || stylelintrc.stylus || stylelintrc.Stylus) {
// apply stylus specific overrides
} |
@TheJaredWilcurt Thanks for chiming in!
Yep, I think we should adopt (as mentioned in #3128 (comment)) the ESLint/Prettier approach of an array of overrides targetting globs of files e.g. {
"rules": {
"declaration-block-trailing-semicolon": true,
"at-rule-no-unknown": true,
},
"overrides": [
{
"files": ["*.sss", "3rd-party/*.sass"],
"rules": {
"declaration-block-trailing-semicolon": false
}
}, {
"files": ["*.less", "*.sass", "*.scss", "*.my-custom-extension"],
"rules": {
"at-rule-no-unknown": false,
}
}
]
}
I think this might be tricky and could muddy the waters. I think we should start with file globs for now as I believe that will address the most common use cases. Once we have the files glob functionality in place, then we can have a think about what we can do, if anything, about the syntax use case e.g. |
I'm down with that! |
@jeddy3 proposition with file globing is the best for flexibility. |
Well, maybe not. Syntax definition may be more suitable for special file like svelte template: see: https://github.com/sveltejs/template/blob/4e3a4089b4f0275964eb10a432dc1c15526a0b4d/src/App.svelte |
The same for Vue SFC |
This will also make it easier to control disables on a file-by-file basis once #3128 is implemented. It will also make it possible to add finer-grained configuration to these rules in the future.
This will also make it easier to control disables on a file-by-file basis once #3128 is implemented. It will also make it possible to add finer-grained configuration to these rules in the future.
This will also make it easier to control disables on a file-by-file basis once #3128 is implemented. It will also make it possible to add finer-grained configuration to these rules in the future.
* Remove unused disable-reporting code This was outmoded by #4973 * Allow disable reporting to be controlled from the config file This will also make it easier to control disables on a file-by-file basis once #3128 is implemented. It will also make it possible to add finer-grained configuration to these rules in the future. * Fix a typo Co-authored-by: Jennifer Thakar <jathak@google.com> * Code review changes Co-authored-by: Jennifer Thakar <jathak@google.com>
It'll help users migrate to For example, someone linting SCSS and CSS:
{
"overrides": [
{
"files": ["**/*.scss"],
"customSyntax": "postcss-scss"
}
]
} |
I think it's a good idea to have it in |
Oops, I added to the release issue checklist but not the milestone. |
How is that work in <!-- example.vue -->
<style lang="scss"></style>
<style lang="less"></style> |
In terms of custom syntax? Someone from the Vue community will need to write a In terms of the Once the {
"overrides": [
{
"files": ["**/*.vue"],
"customSyntax": "postcss-vue"
}
]
}
And simply the following if you're only writing {
"customSyntax": "postcss-vue"
}
In both cases, you'd configure your stylelint rules for whatever is the nested syntax. |
Fantastic! This will also help large mono repo configurations be able to incrementally roll out changes to packages instead of a big bang. |
I'm currently implementing Stylelint in a huge monorepo and having rule overrides per files/paths would help us segregate rules to be warnings in existing files and errors in new files. The incidence number of certain non-fixable rules we'd chosen is so high that it's practically impossible to fix them all manually. A good workaround for us would be to mark the violations in the old files as warnings, but have the rules act as errors in files created in the future. |
@AndreasNasman Thanks for chiming in with your use case. It sounds like combining Please consider contributing if you have time, as the |
Done in #5522 |
I want to set different rules to lint
.css
and.sass
files. It's different syntaxes.These rules are not compatible with
.sass
indented syntax:{}
;
So I want to disable them for
.sass
files, but control them for.css
I created a sandbox repository to test out
postcss-sass
parser with Stylelint, so you can uncomment any incompatible rules mentioned above to see it's false-positiveshttps://github.com/Grawl/stylelint-sass-test
"stylelint": "^8.2.0"
My propose for configuration:
Prettier have this option: https://prettier.io/docs/en/configuration.html#configuration-overrides
#2486 #2593
The text was updated successfully, but these errors were encountered: