Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(stylelint): custom syntax for stylelint v14 (#1065)
* wip * finish some tests and stylelint-config-standard-linaria * remove unnecessary files * update placeholder logic * add isSelector placeholder logic, fix bugs * remove unnecessary atrule logic * cleanup, utils and locationCorrection tests, placeholder consolidation * support styled api, bug fix for ruleset with func in expr * remove changelog, add docs * update comment * add additional style api specs, fix single line css, fix case when suffix is on end of value * add location correction tests * uncomment specs * remove comment * add @linaria namespace * run pnpm changeset * update linting docs, change config to js file * use string instead of require * remove unused eslint disable * fix ts issue * add type Co-authored-by: Tim Kutnick <tim.kutnick@airbnb.com>
- Loading branch information
1 parent
ab510e1
commit ce36da4
Showing
22 changed files
with
2,589 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@linaria/postcss-linaria': patch | ||
'@linaria/stylelint-config-standard-linaria': patch | ||
--- | ||
|
||
Add stylelint v14 custom syntax support |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import type { Document, Node } from 'postcss'; | ||
|
||
import { parse } from '../../src/parse'; | ||
|
||
export function createTestAst(source: string): { | ||
ast: Document; | ||
source: string; | ||
} { | ||
const ast = parse(source) as Document; | ||
|
||
return { ast, source }; | ||
} | ||
|
||
export function getSourceForNodeByLoc(source: string, node: Node): string { | ||
const loc = node.source; | ||
|
||
if (!loc || !loc.start || !loc.end) { | ||
return ''; | ||
} | ||
|
||
const lines = source.split(/\r\n|\n/); | ||
const result: string[] = []; | ||
const startLineIndex = loc.start.line - 1; | ||
const endLineIndex = loc.end.line - 1; | ||
|
||
for (let i = startLineIndex; i < loc.end.line; i++) { | ||
const line = lines[i]; | ||
if (line) { | ||
let offsetStart = 0; | ||
let offsetEnd = line.length; | ||
|
||
if (i === startLineIndex) { | ||
offsetStart = loc.start.column - 1; | ||
} | ||
|
||
if (i === endLineIndex) { | ||
offsetEnd = loc.end.column; | ||
} | ||
|
||
result.push(line.substring(offsetStart, offsetEnd)); | ||
} | ||
} | ||
|
||
return result.join('\n'); | ||
} | ||
|
||
export function getSourceForNodeByRange(source: string, node: Node): string { | ||
if (!node.source || !node.source.start || !node.source.end) { | ||
return ''; | ||
} | ||
|
||
return source.substring(node.source.start.offset, node.source.end.offset + 1); | ||
} | ||
|
||
export const sourceWithExpression = { | ||
ruleset: ` | ||
const expr = 'color: black'; | ||
css\` | ||
$\{expr} | ||
\`; | ||
`, | ||
singleLineRuleset: ` | ||
css\` | ||
\${expr0} { \${expr1}: \${expr2} } | ||
\` | ||
`, | ||
selectorOrAtRule: ` | ||
const expr = '@media (min-width: 100px)'; | ||
css\` | ||
$\{expr} { | ||
color: black; | ||
} | ||
\`; | ||
`, | ||
selectorBeforeExpression: ` | ||
const expr = '.classname'; | ||
css\` | ||
.example $\{expr} { | ||
color: black; | ||
} | ||
\`; | ||
`, | ||
selectorAfterExpression: ` | ||
const expr = '.classname'; | ||
css\` | ||
$\{expr} .example { | ||
color: black; | ||
} | ||
\`; | ||
`, | ||
declarationProperty: ` | ||
const expr = 'color'; | ||
css\` | ||
\${expr}: black; | ||
\`; | ||
`, | ||
declarationValue: ` | ||
const expr = 'black'; | ||
css\` | ||
color: \${expr}; | ||
\`; | ||
`, | ||
declarationMultipleValues: ` | ||
const expr1 = '10px'; | ||
const expr2 = '5px'; | ||
css\` | ||
margin: \${expr1} \${expr2} \${expr1} \${expr2}; | ||
\`; | ||
`, | ||
declarationMixedValues: ` | ||
const expr1 = '10px'; | ||
const expr2 = '5px'; | ||
css\` | ||
margin: \${expr1} 7px \${expr2} 9px; | ||
\`; | ||
`, | ||
combo: ` | ||
css\` | ||
\${expr0} | ||
.foo { | ||
\${expr1}: \${expr2}; | ||
} | ||
\${expr3} { | ||
.bar { | ||
color: black; | ||
} | ||
} | ||
\${expr4} | ||
\`; | ||
`, | ||
}; |
Oops, something went wrong.