Skip to content
Open
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
7 changes: 5 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
type Declaration,
type Value,
type Operator,
} from 'css-tree'
} from '@eslint/css-tree'

const SPACE = ' '
const EMPTY_STRING = ''
Expand Down Expand Up @@ -67,7 +67,7 @@
let comments: number[] = []

function on_comment(_: string, position: CssLocation) {
comments.push(position.start.offset, position.end.offset)

Check failure on line 70 in index.ts

View workflow job for this annotation

GitHub Actions / Check types

Property 'end' does not exist on type 'CssLocation'.

Check failure on line 70 in index.ts

View workflow job for this annotation

GitHub Actions / Check types

Property 'start' does not exist on type 'CssLocation'.
}

let ast = parse(css, {
Expand All @@ -75,7 +75,7 @@
parseAtrulePrelude: false,
parseCustomProperty: true,
parseValue: true,
onComment: on_comment,

Check failure on line 78 in index.ts

View workflow job for this annotation

GitHub Actions / Check types

Type '(_: string, position: CssLocation) => void' is not assignable to type 'OnParseCommentCallback'.
}) as StyleSheet

const NEWLINE = minify ? EMPTY_STRING : '\n'
Expand Down Expand Up @@ -193,7 +193,10 @@
}
case 'Combinator': {
// putting spaces around `child.name` (+ > ~ or ' '), unless the combinator is ' '
buffer += SPACE
// and the combinator is not the first in a nested selectorlist
if (child !== children.first) {
buffer += SPACE
}

if (child.name !== ' ') {
buffer += child.name + SPACE
Expand Down
42 changes: 17 additions & 25 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
},
"devDependencies": {
"@codecov/vite-plugin": "^1.9.1",
"@types/css-tree": "^2.3.11",
"@vitest/coverage-v8": "^4.0.3",
"c8": "^10.1.3",
"oxlint": "^1.24.0",
Expand All @@ -41,9 +40,6 @@
"vite-plugin-dts": "^4.5.4",
"vitest": "^4.0.3"
},
"dependencies": {
"css-tree": "^3.1.0"
},
"files": [
"dist"
],
Expand All @@ -62,5 +58,8 @@
"useTabs": true,
"printWidth": 140,
"singleQuote": true
},
"dependencies": {
"@eslint/css-tree": "^3.6.6"
}
}
57 changes: 34 additions & 23 deletions test/rules.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,19 +182,21 @@ test('formats unknown stuff in curly braces', () => {
expect(actual).toEqual(expected)
})

test('[check broken test] Relaxed nesting: formats nested rules with a selector with a &', () => {
test('Relaxed nesting: formats nested rules with a selector with a &', () => {
let actual = format(`
selector {
a & { color:red }
}
`)
let expected = `selector {
a & { color:red }
a & {
color: red;
}
}`
expect(actual).toEqual(expected)
})

test.skip('Relaxed nesting: formats nested rules with a selector with a &', () => {
test('Relaxed nesting: formats nested rules with a selector with a &', () => {
let actual = format(`
selector {
a & { color:red }
Expand All @@ -208,19 +210,21 @@ test.skip('Relaxed nesting: formats nested rules with a selector with a &', () =
expect(actual).toEqual(expected)
})

test('[check broken test] Relaxed nesting: formats nested rules with a selector without a &', () => {
test('Relaxed nesting: formats nested rules with a selector without a &', () => {
let actual = format(`
selector {
a { color:red }
}
`)
let expected = `selector {
a { color:red }
a {
color: red;
}
}`
expect(actual).toEqual(expected)
})

test.skip('Relaxed nesting: formats nested rules with a selector without a &', () => {
test('Relaxed nesting: formats nested rules with a selector without a &', () => {
let actual = format(`
selector {
a { color:red }
Expand All @@ -234,23 +238,7 @@ test.skip('Relaxed nesting: formats nested rules with a selector without a &', (
expect(actual).toEqual(expected)
})

test('[check broken test] Relaxed nesting: formats nested rules with a selector starting with a selector combinator', () => {
let actual = format(`
selector {
> a { color:red }
~ a { color:red }
+ a { color:red }
}
`)
let expected = `selector {
> a { color:red }
~ a { color:red }
+ a { color:red }
}`
expect(actual).toEqual(expected)
})

test.skip('Relaxed nesting: formats nested rules with a selector starting with a selector combinator', () => {
test('Relaxed nesting: formats nested rules with a selector starting with a selector combinator', () => {
let actual = format(`
selector {
> a { color:red }
Expand Down Expand Up @@ -285,3 +273,26 @@ test('handles syntax errors: premature closed block', () => {
let expected = 'a {\n\tmumblejumble: ;\n}'
expect(actual).toEqual(expected)
})
test('Relaxed nesting: formats nested rules with a selector starting with a selector combinator and &', () => {
let actual = format(`
selector {
& > a { color:red }
& ~ a { color:red }
& + a { color:red }
}
`)
let expected = `selector {
& > a {
color: red;
}

& ~ a {
color: red;
}

& + a {
color: red;
}
}`
expect(actual).toEqual(expected)
})
2 changes: 1 addition & 1 deletion vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default defineConfig({
rollupOptions: {
// make sure to externalize deps that shouldn't be bundled
// into your library
external: ['css-tree'],
external: ['@eslint/css-tree'],
},
},
plugins: [
Expand Down
Loading