-
Notifications
You must be signed in to change notification settings - Fork 21
[BOOKINGSG-9317][GZ] include linaria css in stylelint #1157
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
Draft
ghazwan-gt
wants to merge
18
commits into
pre-release/v4
Choose a base branch
from
BOOKINGSG-9317/styelint-linaria
base: pre-release/v4
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
1717971
[BOOKINGSG-9317][GZ] update stylelint config to include linaria css i…
ghazwanmuhammad 5782846
[BOOKINGSG-9317][GZ] add eslint rule to prevent negative interpolatio…
ghazwanmuhammad c7e9f7e
[BOOKINGSG-9317][GZ] change stylelint config to mjs
ghazwanmuhammad a1162e4
[BOOKINGSG-9317][GZ] separate local eslint rules to its own file
ghazwanmuhammad 687611d
[BOOKINGSG-9317][GZ] ignore class selector on linaria styling file
ghazwanmuhammad 6e0342d
[BOOKINGSG-9317][GZ] add stylelint rule to ignore linaria placeholder…
ghazwanmuhammad 41918aa
[BOOKINGSG-9317][GZ] add stylelint rule to ignore some pseudo class a…
ghazwanmuhammad ce02b4d
[BOOKINGSG-9317][GZ] add stylelint rule to ignore font family quote a…
ghazwanmuhammad 1274d91
[BOOKINGSG-9317][GZ] update prettier config to have longer length bef…
ghazwanmuhammad eb7b903
[BOOKINGSG-9317][GZ] update eslint import path
ghazwanmuhammad 41ad6f5
[BOOKINGSG-9317][GZ] apply lint fix
ghazwanmuhammad e0b2fce
[BOOKINGSG-9317][GZ] ignore playwright report
ghazwanmuhammad fe72b32
[BOOKINGSG-9317][GZ] resolve not linting due to double slash comment
ghazwanmuhammad 589be9d
[BOOKINGSG-9317][GZ] update stylelint config path in vscode setting
ghazwanmuhammad ef9e588
[BOOKINGSG-9317][GZ] update removed tokens
ghazwanmuhammad 142cdd8
[BOOKINGSG-9317][GZ] update removed properties
ghazwanmuhammad 820c14b
[BOOKINGSG-9317][GZ] disable stylelint for css properties ordering
ghazwanmuhammad 636aa7a
[BOOKINGSG-9317][GZ] removing config flag
ghazwanmuhammad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1,16 +1,22 @@ | ||
| { | ||
| "trailingComma": "es5", | ||
| "tabWidth": 4, | ||
| "semi": true, | ||
| "singleQuote": false, | ||
| "bracketSpacing": true, | ||
| "arrowParens": "always", | ||
| "overrides": [ | ||
| { | ||
| "files": ".github/**/*.yml", | ||
| "options": { | ||
| "tabWidth": 2 | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| "trailingComma": "es5", | ||
| "tabWidth": 4, | ||
| "semi": true, | ||
| "singleQuote": false, | ||
| "bracketSpacing": true, | ||
| "arrowParens": "always", | ||
| "overrides": [ | ||
| { | ||
| "files": "**/*.styles.ts", | ||
| "options": { | ||
| "printWidth": 120 | ||
| } | ||
| }, | ||
| { | ||
| "files": ".github/**/*.yml", | ||
| "options": { | ||
| "tabWidth": 2 | ||
| } | ||
| } | ||
| ] | ||
| } | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| node_modules | ||
| dist | ||
| */coverage/lcov-report | ||
| */coverage/lcov-report | ||
| playwright-report |
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,11 @@ | ||
| import { importPathPreferencesRule } from "./import-path-preferences.rule.mjs"; | ||
| import { noNegativeLinariaInterpolationRule } from "./no-negative-linaria-interpolation.rule.mjs"; | ||
| import { styleNamespaceImportRule } from "./style-namespace-import.rule.mjs"; | ||
|
|
||
| export default { | ||
| rules: { | ||
| "import-path-preferences": importPathPreferencesRule, | ||
| "style-namespace-import": styleNamespaceImportRule, | ||
| "no-negative-linaria-interpolation": noNegativeLinariaInterpolationRule, | ||
| }, | ||
| }; |
81 changes: 81 additions & 0 deletions
81
eslint-local-rules/no-negative-linaria-interpolation.rule.mjs
This file contains hidden or 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,81 @@ | ||
| export const noNegativeLinariaInterpolationRule = { | ||
| meta: { | ||
| type: "problem", | ||
| docs: { | ||
| description: | ||
| "Disallow negative Linaria interpolations like -${token} in css templates.", | ||
| }, | ||
| fixable: "code", | ||
| schema: [], | ||
| messages: { | ||
| negativeLinariaInterpolation: | ||
| "Avoid -${...} in Linaria css templates. Use calc(${...} * -1) instead.", | ||
| }, | ||
| }, | ||
| create(context) { | ||
| return { | ||
| TaggedTemplateExpression(node) { | ||
| // Only lint Linaria `css` tagged template literals. | ||
| if ( | ||
| node.tag.type !== "Identifier" || | ||
| node.tag.name !== "css" || | ||
| node.quasi.type !== "TemplateLiteral" | ||
| ) { | ||
| return; | ||
| } | ||
|
|
||
| const template = node.quasi; | ||
| for (let i = 0; i < template.expressions.length; i += 1) { | ||
| const beforeExpression = template.quasis[i]?.value?.raw; | ||
| if (!beforeExpression) continue; | ||
|
|
||
| // Detect patterns like `...: -${token};` where unary minus is | ||
| // applied before interpolation and compiles to invalid CSS values. | ||
| const negativePrefixMatch = beforeExpression.match(/-\s*$/); | ||
| if (negativePrefixMatch) { | ||
| const beforeMinus = beforeExpression.slice( | ||
| 0, | ||
| beforeExpression.length - | ||
| negativePrefixMatch[0].length | ||
| ); | ||
| const previousNonWhitespace = | ||
| beforeMinus.match(/\S\s*$/)?.[0]?.trim() || ""; | ||
|
|
||
| // Only flag unary negatives like `: -${x}` or `(-${x}`. | ||
| // Skip binary subtraction contexts like `100% - ${x}`. | ||
| if ( | ||
| previousNonWhitespace && | ||
| ![":", "(", ","].includes(previousNonWhitespace) | ||
| ) { | ||
| continue; | ||
| } | ||
|
|
||
| context.report({ | ||
| node: template.expressions[i], | ||
| messageId: "negativeLinariaInterpolation", | ||
| fix(fixer) { | ||
| const expression = template.expressions[i]; | ||
| const negativePrefixLength = | ||
| negativePrefixMatch[0].length; | ||
| // Replace from the trailing `-${` prefix to the closing `}` | ||
| // of the interpolation with `calc(${expr} * -1)`. | ||
| const replacementStart = | ||
| expression.range[0] - | ||
| negativePrefixLength - | ||
| 2; | ||
| const replacementEnd = expression.range[1] + 1; | ||
| const expressionText = | ||
| context.sourceCode.getText(expression); | ||
|
|
||
| return fixer.replaceTextRange( | ||
| [replacementStart, replacementEnd], | ||
| `calc($\{${expressionText}} * -1)` | ||
| ); | ||
| }, | ||
| }); | ||
| } | ||
| } | ||
| }, | ||
| }; | ||
| }, | ||
| }; |
This file contains hidden or 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,55 @@ | ||
| const SAME_DIR_STYLE_MODULE_IMPORT_PATTERN = /^\.\/[^/]+\.styles$/; | ||
|
|
||
| export const styleNamespaceImportRule = { | ||
| meta: { | ||
| type: "suggestion", | ||
| docs: { | ||
| description: | ||
| "Enforce namespace imports for style modules (*.styles).", | ||
| }, | ||
| fixable: "code", | ||
| schema: [], | ||
| messages: { | ||
| namespaceStyleImport: | ||
| "Import style modules using a namespace import (e.g. import * as styles from './component.styles').", | ||
| }, | ||
| }, | ||
| create(context) { | ||
| return { | ||
| ImportDeclaration(node) { | ||
| if (!node?.source || typeof node.source.value !== "string") { | ||
| return; | ||
| } | ||
|
|
||
| const importSource = node.source.value; | ||
| if (!SAME_DIR_STYLE_MODULE_IMPORT_PATTERN.test(importSource)) { | ||
| return; | ||
| } | ||
|
|
||
| // Type-only imports are ignored to avoid rewriting TS type flows. | ||
| if (node.importKind === "type") return; | ||
|
|
||
| // Side-effect imports are allowed (no bindings to enforce). | ||
| if (!node.specifiers.length) return; | ||
|
|
||
| const hasOnlyNamespaceSpecifiers = node.specifiers.every( | ||
| (specifier) => specifier.type === "ImportNamespaceSpecifier" | ||
| ); | ||
| if (hasOnlyNamespaceSpecifiers) return; | ||
|
|
||
| context.report({ | ||
| node, | ||
| messageId: "namespaceStyleImport", | ||
| // TODO: Autofix is disabled until linaria migration is complete. | ||
|
|
||
| // fix(fixer) { | ||
| // const quote = getQuote(node.source.raw); | ||
| // const localName = getStyleNamespaceLocalName(node); | ||
| // const fixedImport = `import * as ${localName} from ${quote}${importSource}${quote};`; | ||
| // return fixer.replaceText(node, fixedImport); | ||
| // }, | ||
| }); | ||
| }, | ||
| }; | ||
| }, | ||
| }; |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is this for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to help us preventing the linaria's postcss which wrongly process interpolation when it is on multiple lines