Skip to content

Commit b04f025

Browse files
authored
fix(postcss-linaria): enable CI tests (#1466)
* fix(postcss-linaria): enable CI tests * chore: add changeset for postcss-linaria fixes
1 parent 02bc1d4 commit b04f025

File tree

6 files changed

+29
-5
lines changed

6 files changed

+29
-5
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@linaria/postcss-linaria': patch
3+
---
4+
5+
Fix `@linaria/postcss-linaria` placeholder naming and source location correction, and ensure stylelint integration resolves configs correctly.

packages/postcss-linaria/__tests__/stylelint.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { resolve } from 'path';
2+
13
import stylelint, { type Config } from 'stylelint';
24

35
// importing from the package would create circular dependency
@@ -7,6 +9,11 @@ import config from '../../stylelint-config-standard-linaria/src';
79

810
// note: need to run pnpm install to pick up updates from any parse/stringify changes
911
describe('stylelint', () => {
12+
const configBasedir = resolve(
13+
__dirname,
14+
'../../stylelint-config-standard-linaria'
15+
);
16+
1017
it('should not error with valid syntax', async () => {
1118
const source = `
1219
css\`
@@ -26,6 +33,7 @@ describe('stylelint', () => {
2633
const result = await stylelint.lint({
2734
code: source,
2835
config: config as Config,
36+
configBasedir,
2937
});
3038

3139
expect(result.errored).toEqual(false);
@@ -46,6 +54,7 @@ describe('stylelint', () => {
4654
},
4755
} as Config,
4856
fix: true,
57+
configBasedir,
4958
});
5059
expect(result.errored).toEqual(false);
5160
expect(result.output).toMatchInlineSnapshot(`
@@ -71,6 +80,7 @@ describe('stylelint', () => {
7180
},
7281
} as Config,
7382
fix: true,
83+
configBasedir,
7484
});
7585
expect(result.errored).toEqual(false);
7686
expect(result.output).toMatchInlineSnapshot(`
@@ -97,6 +107,7 @@ describe('stylelint', () => {
97107
},
98108
} as Config,
99109
fix: true,
110+
configBasedir,
100111
});
101112
expect(result.output).toMatchInlineSnapshot(`
102113
"
@@ -124,6 +135,7 @@ describe('stylelint', () => {
124135
indentation: 4,
125136
},
126137
} as Config,
138+
configBasedir,
127139
});
128140

129141
expect(result.errored).toEqual(false);

packages/postcss-linaria/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"build:esm": "babel src --out-dir esm --extensions '.js,.jsx,.ts,.tsx' --source-maps --delete-dir-on-start",
3030
"build:lib": "cross-env NODE_ENV=legacy babel src --out-dir lib --extensions '.js,.jsx,.ts,.tsx' --source-maps --delete-dir-on-start",
3131
"typecheck": "tsc --noEmit --composite false",
32+
"test": "jest --config ../../jest.config.js --rootDir .",
3233
"watch": "pnpm build:lib --watch & pnpm build:esm --watch & pnpm build:declarations --watch"
3334
},
3435
"dependencies": {

packages/postcss-linaria/src/locationCorrection.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ const correctLocation = (
99
loc: Position,
1010
baseIndentations: Map<number, number>,
1111
sourceAsString: string,
12-
prefixOffsets?: { lines: number; offset: number }
12+
prefixOffsets?: { lines: number; offset: number },
13+
kind: 'start' | 'end' = 'start'
1314
): Position => {
1415
if (!node.quasi.loc || !node.quasi.range) {
1516
return loc;
@@ -19,7 +20,7 @@ const correctLocation = (
1920
const nodeLoc = node.quasi.loc;
2021
const nodeOffset = node.quasi.range[0];
2122
let lineOffset = nodeLoc.start.line - 1;
22-
let newOffset = loc.offset + nodeOffset + 1;
23+
let newOffset = loc.offset + nodeOffset + (kind === 'start' ? 1 : 0);
2324
let currentLine = 1;
2425
let columnOffset = nodeLoc.start.column + 1;
2526

@@ -276,7 +277,8 @@ export function locationCorrectionWalker(
276277
node.source.start,
277278
baseIndentations,
278279
sourceAsString,
279-
root.raws.linariaPrefixOffsets
280+
root.raws.linariaPrefixOffsets,
281+
'start'
280282
);
281283
}
282284
if (node.source?.end) {
@@ -285,7 +287,8 @@ export function locationCorrectionWalker(
285287
node.source.end,
286288
baseIndentations,
287289
sourceAsString,
288-
root.raws.linariaPrefixOffsets
290+
root.raws.linariaPrefixOffsets,
291+
'end'
289292
);
290293
}
291294
};

packages/postcss-linaria/src/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const isRuleSet = (sourceAsString: string, indexAfterExpression: number) => {
5454
);
5555
};
5656

57-
export const placeholderText = 'pcss_lin';
57+
export const placeholderText = 'pcss-lin';
5858

5959
export const createPlaceholder = (
6060
i: number,

turbo.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
"@linaria/react#test": {
2525
"dependsOn": ["@linaria/core#build"]
2626
},
27+
"@linaria/postcss-linaria#test": {
28+
"dependsOn": ["@linaria/postcss-linaria#build"]
29+
},
2730
"@linaria/testkit#test": {
2831
"dependsOn": ["^build"]
2932
},

0 commit comments

Comments
 (0)