Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/rules/no-dupe-style-properties.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import type { AST } from "svelte-eslint-parser"
import { createRule } from "../utils"
import type { SvelteStyleInlineRoot, SvelteStyleRoot } from "../utils/css-utils"
import type {
SvelteStyleInterpolation,
SvelteStyleRoot,
} from "../utils/css-utils"
import { parseStyleAttributeValue } from "../utils/css-utils"

export default createRule("no-dupe-style-properties", {
Expand Down Expand Up @@ -76,9 +79,9 @@ export default createRule("no-dupe-style-properties", {
}

/** Iterate the style decl set from style root */
function* iterateStyleDeclSetFromStyleRoot(
root: SvelteStyleRoot | SvelteStyleInlineRoot,
): Iterable<StyleDeclSet> {
function* iterateStyleDeclSetFromStyleRoot<
E extends SvelteStyleInterpolation,
>(root: SvelteStyleRoot<E>): Iterable<StyleDeclSet> {
for (const child of root.nodes) {
if (child.type === "decl") {
yield {
Expand Down
11 changes: 7 additions & 4 deletions src/rules/no-shorthand-style-property-overrides.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import type { AST } from "svelte-eslint-parser"
import { createRule } from "../utils"
import type { SvelteStyleInlineRoot, SvelteStyleRoot } from "../utils/css-utils"
import type {
SvelteStyleInterpolation,
SvelteStyleRoot,
} from "../utils/css-utils"
import {
getVendorPrefix,
stripVendorPrefix,
Expand Down Expand Up @@ -91,9 +94,9 @@ export default createRule("no-shorthand-style-property-overrides", {
}

/** Iterate the style decl set from style root */
function* iterateStyleDeclSetFromStyleRoot(
root: SvelteStyleRoot | SvelteStyleInlineRoot,
): Iterable<StyleDeclSet> {
function* iterateStyleDeclSetFromStyleRoot<
E extends SvelteStyleInterpolation,
>(root: SvelteStyleRoot<E>): Iterable<StyleDeclSet> {
for (const child of root.nodes) {
if (child.type === "decl") {
yield {
Expand Down
23 changes: 15 additions & 8 deletions src/rules/prefer-style-directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default createRule("prefer-style-directive", {
*/
function processStyleValue(
node: AST.SvelteAttribute,
root: SvelteStyleRoot,
root: SvelteStyleRoot<AST.SvelteMustacheTagText>,
) {
for (const child of root.nodes) {
if (child.type === "decl") {
Expand All @@ -54,10 +54,15 @@ export default createRule("prefer-style-directive", {
*/
function processDeclaration(
attrNode: AST.SvelteAttribute,
root: SvelteStyleRoot,
decl: SvelteStyleDeclaration,
root: SvelteStyleRoot<AST.SvelteMustacheTagText>,
decl: SvelteStyleDeclaration<AST.SvelteMustacheTagText>,
) {
if (decl.important || decl.unsafe) return
if (
decl.important ||
decl.unknownInterpolations.length ||
decl.prop.interpolations.length
)
return
if (
attrNode.parent.attributes.some(
(attr) =>
Expand Down Expand Up @@ -101,8 +106,8 @@ export default createRule("prefer-style-directive", {
*/
function processInline(
attrNode: AST.SvelteAttribute,
root: SvelteStyleRoot,
inline: SvelteStyleInline,
root: SvelteStyleRoot<AST.SvelteMustacheTagText>,
inline: SvelteStyleInline<AST.SvelteMustacheTagText>,
) {
const node = inline.node.expression

Expand Down Expand Up @@ -194,8 +199,10 @@ export default createRule("prefer-style-directive", {
/** Remove style */
function removeStyle(
fixer: RuleFixer,
root: SvelteStyleRoot,
node: SvelteStyleDeclaration | SvelteStyleInline,
root: SvelteStyleRoot<AST.SvelteMustacheTagText>,
node:
| SvelteStyleDeclaration<AST.SvelteMustacheTagText>
| SvelteStyleInline<AST.SvelteMustacheTagText>,
) {
const index = root.nodes.indexOf(node)
const after = root.nodes[index + 1]
Expand Down
8 changes: 6 additions & 2 deletions src/rules/require-optimized-style-attribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,22 @@ export default createRule("require-optimized-style-attribute", {
}
const root = parseStyleAttributeValue(node, context)
if (!root) {
context.report({
node,
messageId: "complex",
})
return
}

for (const child of root.nodes) {
if (child.type === "decl") {
if (child.unsafe) {
if (child.unknownInterpolations.length) {
context.report({
node,
loc: child.loc,
messageId: "complex",
})
} else if (child.prop.name.includes("{")) {
} else if (child.prop.interpolations.length) {
context.report({
node,
loc: child.prop.loc,
Expand Down
Loading