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 support for inline styles #6833
Comments
I'd be more than happy to try to fix it, and it would be even better if someone could give me some guidance. Thanks. |
@yoyo837 Thanks for the report with the reproducible example. I can confirm the error with this minimal reproducible demo: <a style="--swipe-height: 100%">
</a> {
"customSyntax": "postcss-html",
"rules": {
"custom-property-empty-line-before": "always"
}
} Since this error seems specific for only HTML syntax, I think we can avoid the error by just turning the rule off like this: {
"overrides": [
{
"files": ["**/*.html"],
"rules": {
"custom-property-empty-line-before": null
}
}
]
} What do you think? |
In |
@yoyo837 Does this case in a demo match a |
See my case in a demo. |
@yoyo837 Handling the two cases you provided seems difficult to me. 🤔 <template>
<!-- Should not report custom-property-empty-line-before -->
<p style="--swipe-height: 100%;">123</p>
</template>
<style lang="scss">
a {
// Should report `custom-property-empty-line-before` if there is no empty line
--swipe-height: 100%;
}
</style>
|
Currently we can turn off the Its difficult point is that it is an inline style of html, so this is considered a bug for stylelint you think? Or some point that can be improved, can stylelint do something for it? In fact, there should be similar situations in other rules. |
I think this is not a bug of Stylelint because $ node -e 'require("postcss-html").parse(`<p style="--height: 100%;">123</p>`).walkDecls(console.log)'
<ref *1> Declaration {
raws: { before: '', between: ': ' },
type: 'decl',
parent: Root {
raws: {
semicolon: true,
after: '',
codeBefore: '<p style="',
codeAfter: '">123</p>'
},
type: 'root',
nodes: [ [Circular *1] ],
source: {
input: [Input],
start: [Object],
inline: true,
lang: 'css',
syntax: [Object]
},
lastEach: 2,
indexes: { '2': 0 },
document: Document {
raws: {},
type: 'document',
nodes: [Array],
source: [Object],
[Symbol(isClean)]: false,
[Symbol(my)]: true
},
[Symbol(isClean)]: false,
[Symbol(my)]: true
},
source: {
start: { offset: 10, line: 1, column: 11 },
input: Input {
css: '--height: 100%;',
hasBOM: false,
id: '<input css NMF65H>',
[Symbol(fromOffsetCache)]: [Array]
},
end: { offset: 24, line: 1, column: 25 }
},
prop: '--height',
value: '100%',
[Symbol(isClean)]: false,
[Symbol(my)]: true
} 0 Please note that the
In this case, the
I think a package using |
However, What if |
I mean, <!--
postcss-html gives us a blank line?
If non-first css properties in inline styles, it How?
-->
<p style="color:red;--swipe-height: 100%;">123</p> |
We can see minimal reproduction with this demo using Also, I find a workaround to fix this problem: --- a/lib/rules/custom-property-empty-line-before/index.js
+++ b/lib/rules/custom-property-empty-line-before/index.js
@@ -78,7 +78,7 @@ const rule = (primary, secondaryOptions, context) => {
if (
optionsMatches(secondaryOptions, 'ignore', 'inside-single-line-block') &&
parent != null &&
- (isAtRule(parent) || isRule(parent)) &&
+ (isAtRule(parent) || isRule(parent) || 'document' in parent) &&
isSingleLineString(blockString(parent))
) {
return; This workaround uses the |
Thanks for the code analysis, I think before talking about how to fix it with code, we should first confirm that where it should be fixed, in |
Ideally, I don't think Stylelint's built-in rules should fix the problem due to an HTML inline A workaround like #6833 (comment) may be possible, but there is no assurance with other syntaxes. |
Ok, Thanks for your reply. Ref: #5999 |
Maybe we can do something like #4726, Is this the same as what you said? |
No. <a style="--foo: 1em;"></a> but it cannot fix: <a style="--foo: 1em; --bar: 1em;"></a> The workaround that I mentioned on #6833 (comment) ignores |
FYI. #5999 was closed because we planned to remove |
Ok, so should this issue be marked as |
Let's keep it open to prevent someone from reporting similar issues for a while. Also, possibly, a solution may be found. |
Is there a way to disable the rule for that specific line in Svelte and Vue components? Using the quick fix in VSCode doesn't produce anything very useful:
just becomes
which not only wrecks the output, but doesn't actually disable the rule. Similarly, choosing "disable for the entire file" just puts that comment on line 1 — so it will still be treated as HTML and rendered! While the example above could be moved to a style definition, my code contains
which has to be there because Svelte variables can be interpolated into HTML but not CSS. I don't want to disable the rule globally, but I do need to mark this line as being OK, as passing a Stylelint check is required to pass CI. That said, setting CSS variables reactively is the only time inline styles are used in this project, so I'd be happy with a way of telling Stylelint to completely ignore inline styles. Is that possible? |
@unikitty37 Yeah, What you want is also what I want, we can not do that by any code in this moment. |
@yoyo837 I've managed to work around it for Svelte. Instead of Looking at the Vue docs, maybe this would work? (I assume you're on Vue 3…) <script>
const styleObject = reactive({ "--swipe-height": "100%" })
</script>
<p :style="styleObject">…</p> |
@unikitty37 Yes, this is a works solution, but it restricts me from writing style freely. |
related: ota-meshi/postcss-html#38 |
What steps are needed to reproduce the bug?
What Stylelint configuration is needed to reproduce the bug?
How did you run Stylelint?
Cli with
stylelint '**/*.vue'
Which version of Stylelint or dependencies are you using?
15.6.1
What did you expect to happen?
No problems to be reported
What actually happened?
custom-property-empty-line-before
is reported.Does the bug relate to non-standard syntax?
No response
Proposal to fix the bug
No response
The text was updated successfully, but these errors were encountered: