Skip to content
Draft
Show file tree
Hide file tree
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 May 6, 2026
5782846
[BOOKINGSG-9317][GZ] add eslint rule to prevent negative interpolatio…
ghazwanmuhammad May 6, 2026
c7e9f7e
[BOOKINGSG-9317][GZ] change stylelint config to mjs
ghazwanmuhammad May 7, 2026
a1162e4
[BOOKINGSG-9317][GZ] separate local eslint rules to its own file
ghazwanmuhammad May 7, 2026
687611d
[BOOKINGSG-9317][GZ] ignore class selector on linaria styling file
ghazwanmuhammad May 7, 2026
6e0342d
[BOOKINGSG-9317][GZ] add stylelint rule to ignore linaria placeholder…
ghazwanmuhammad May 7, 2026
41918aa
[BOOKINGSG-9317][GZ] add stylelint rule to ignore some pseudo class a…
ghazwanmuhammad May 7, 2026
ce02b4d
[BOOKINGSG-9317][GZ] add stylelint rule to ignore font family quote a…
ghazwanmuhammad May 7, 2026
1274d91
[BOOKINGSG-9317][GZ] update prettier config to have longer length bef…
ghazwanmuhammad May 7, 2026
eb7b903
[BOOKINGSG-9317][GZ] update eslint import path
ghazwanmuhammad May 7, 2026
41ad6f5
[BOOKINGSG-9317][GZ] apply lint fix
ghazwanmuhammad May 7, 2026
e0b2fce
[BOOKINGSG-9317][GZ] ignore playwright report
ghazwanmuhammad May 7, 2026
fe72b32
[BOOKINGSG-9317][GZ] resolve not linting due to double slash comment
ghazwanmuhammad May 7, 2026
589be9d
[BOOKINGSG-9317][GZ] update stylelint config path in vscode setting
ghazwanmuhammad May 7, 2026
ef9e588
[BOOKINGSG-9317][GZ] update removed tokens
ghazwanmuhammad May 7, 2026
142cdd8
[BOOKINGSG-9317][GZ] update removed properties
ghazwanmuhammad May 7, 2026
820c14b
[BOOKINGSG-9317][GZ] disable stylelint for css properties ordering
ghazwanmuhammad May 8, 2026
636aa7a
[BOOKINGSG-9317][GZ] removing config flag
ghazwanmuhammad May 8, 2026
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
36 changes: 21 additions & 15 deletions .prettierrc
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
}
Comment on lines +10 to +13
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this for?

Copy link
Copy Markdown
Author

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

},
{
"files": ".github/**/*.yml",
"options": {
"tabWidth": 2
}
}
]
}
3 changes: 2 additions & 1 deletion .stylelintignore
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
15 changes: 0 additions & 15 deletions .stylelintrc.json

This file was deleted.

10 changes: 9 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@
"typescript",
"typescriptreact"
],
"stylelint.validate": ["css", "postcss", "scss", "less"],
"stylelint.validate": [
"css",
"postcss",
"scss",
"less",
"typescript",
"typescriptreact"
],
"stylelint.configFile": "${workspaceFolder}/stylelint.config.mjs",
"auto-close-tag.activationOnLanguage": [
"html",
"javascriptreact",
Expand Down
2 changes: 1 addition & 1 deletion e2e/nextjs-app/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineConfig, globalIgnores } from "eslint/config";
import nextVitals from "eslint-config-next/core-web-vitals";
import nextTs from "eslint-config-next/typescript";
import localRules from "../../eslint-local-rules/import-path-preferences.mjs";
import localRules from "../../eslint-local-rules/index.mjs";

const eslintConfig = defineConfig([
...nextVitals,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const RELATIVE_STORYBOOK_COMMON_PATTERN =
const SRC_IN_STORIES_OR_TESTS_PATTERN = /^(?:\.\.\/)+src(?:\/|$)/;
const STORYBOOK_COMMON_IN_STORIES_PATTERN =
/^(?:(?:\.\.\/)+|\.\/)storybook-common(?:\/|$)/;
const SAME_DIR_STYLE_MODULE_IMPORT_PATTERN = /^\.\/[^/]+\.styles$/;

function normalizePath(filePath) {
return filePath.replaceAll("\\", "/");
Expand All @@ -40,20 +39,6 @@ function getQuote(rawSource) {
return quote === "'" || quote === '"' ? quote : '"';
}

function getStyleNamespaceLocalName(node) {
const namespaceSpecifier = node.specifiers.find(
(specifier) => specifier.type === "ImportNamespaceSpecifier"
);
if (namespaceSpecifier) return namespaceSpecifier.local.name;

const defaultSpecifier = node.specifiers.find(
(specifier) => specifier.type === "ImportDefaultSpecifier"
);
if (defaultSpecifier) return defaultSpecifier.local.name;

return "styles";
}

function toKebabCase(value) {
return value
.replaceAll(/([a-z0-9])([A-Z])/g, "$1-$2")
Expand Down Expand Up @@ -201,7 +186,7 @@ function getMessageId(zone, importSource) {
return null;
}

const importPathPreferencesRule = {
export const importPathPreferencesRule = {
meta: {
type: "suggestion",
docs: {
Expand Down Expand Up @@ -259,64 +244,3 @@ const importPathPreferencesRule = {
};
},
};

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);
// },
});
},
};
},
};

export default {
rules: {
"import-path-preferences": importPathPreferencesRule,
"style-namespace-import": styleNamespaceImportRule,
},
};
11 changes: 11 additions & 0 deletions eslint-local-rules/index.mjs
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 eslint-local-rules/no-negative-linaria-interpolation.rule.mjs
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)`
);
},
});
}
}
},
};
},
};
55 changes: 55 additions & 0 deletions eslint-local-rules/style-namespace-import.rule.mjs
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);
// },
});
},
};
},
};
3 changes: 2 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import pluginSimpleImportSort from "eslint-plugin-simple-import-sort";
import storybook from "eslint-plugin-storybook";
import globals from "globals";

import localRules from "./eslint-local-rules/import-path-preferences.mjs";
import localRules from "./eslint-local-rules/index.mjs";

const sourceFileGlobs = ["**/*.{js,jsx,mjs,cjs,ts,tsx}"];
const reactSourceFileGlobs = ["**/*.{js,jsx,ts,tsx}"];
Expand Down Expand Up @@ -176,6 +176,7 @@ export default defineConfig([
rules: {
"local/import-path-preferences": "warn",
"local/style-namespace-import": "warn",
"local/no-negative-linaria-interpolation": "error",
"react-hooks/exhaustive-deps": [
"warn",
{
Expand Down
Loading