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 media-feature-range-notation
autofix
#6501
Comments
It sounds postcss-media-query-parser could be replaced! $ git grep postcss-media-query-parser lib/
lib/rules/media-feature-name-allowed-list/index.js:8:const mediaParser = require('postcss-media-query-parser').default;
lib/rules/media-feature-name-case/index.js:7:const mediaParser = require('postcss-media-query-parser').default;
lib/rules/media-feature-name-disallowed-list/index.js:8:const mediaParser = require('postcss-media-query-parser').default;
lib/rules/media-feature-name-no-unknown/index.js:8:const mediaParser = require('postcss-media-query-parser').default;
lib/rules/media-feature-name-value-allowed-list/index.js:3:const mediaParser = require('postcss-media-query-parser').default;
lib/rules/no-duplicate-at-import-rules/index.js:3:const mediaParser = require('postcss-media-query-parser').default;
lib/rules/rangeContextNodeParser.js:22: * @param {import('postcss-media-query-parser').Node} node
lib/rules/unit-disallowed-list/index.js:6:const mediaParser = require('postcss-media-query-parser').default;
lib/rules/unit-disallowed-list/index.js:29: * @param {import('postcss-media-query-parser').Child} mediaFeatureNode
lib/rules/unit-no-unknown/index.js:9:const mediaParser = require('postcss-media-query-parser').default; |
Let us know if you need any help using our media query list parser. I needed it for fallback plugins but haven't done the important bits for the wider community.
It is fully typed, so that helps a bit. I will gladly spend time on docs and some more high level functions if there is a community need for this. |
That would be amazing as we've quite a few existing and upcoming rules that would make use of it! |
After reading this comment I realized that I left things vaguely here :) It is not easy for me to provide better documentation and/or a more ergonomic API without specific use cases. I've opened an issue to collect use cases here : csstools/postcss-plugins#763 |
I've been converting a few of the existing stylelint rules to our media query parser and ran into an issue. Our parser is unable to handle sass, less and other non standard syntaxes. For example : This looks like a plain media feature with a name and a value but our parser will parse this as
It is possible to recover from encountering a Was there a specific reason to replace the current parser in use in styelint? |
@romainmenke Thanks for the investigation. The reason we need another parser is that postcss-media-query-parser is outdated (last published 6 years ago) and doesn't parse new syntaxes. |
That's fantastic, thank you! (Although, be sure to avoid any of the media query rules we're deprecating as we'll be removing them in the next major release after 15.0.0).
That's totally OK. The built-in rules are geared towards standard CSS. We use the if (!isStandardSyntaxMediaQueryList(atRule.params) return;
const mediaQueryList = parse(atRule.params);
As @ybiquitous mentioned, the outdated parser we currently use doesn't support some modern CSS syntax, specifically modern range context notation. We current hack around it by using the postcss-value-parser to parse media queries in a range context 😬 . A modern media list parser that allows to do things like walk media feature names regardless of whether it's written in prefix ( |
That is good to know! I am converting these anyway, but I don't plan to submit a patch for this.
This is one of the thing that immediately became clear.
That allows you to do :
Also good to know :) |
What is the problem you're trying to solve?
The rule isn't autofixable.
What solution would you like to see?
Have it autofixable so that:
*-notation
rulesSee #6497 (comment)
It'll only be for the more modern
"context"
option as that addresses the limitations of the prefix approach.We could reach for a new media-query-list-parser.
It won't combine media features. For example:
Becomes:
Rather than:
I've labelled the issue as ready to implement. Please consider contributing if anyone has time.
There are steps to add autofix to a rule in the Developer guide.
The text was updated successfully, but these errors were encountered: