Skip to content

Commit 7352ddc

Browse files
committed
[FIX] Config: check stylesheets scope
The style that we define in our component can sometimes interfere within Odoo. This revision adds a step to force the style to be scoped to 'o-spreadsheet'. Task: 4629441
1 parent 8bd57c6 commit 7352ddc

3 files changed

Lines changed: 51 additions & 5 deletions

File tree

.husky/pre-commit

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ if [ "$HUSKY_PRE_COMMIT" != 0 ]; then
2525
exec git diff --cached --color | grep -nE $consoleregexp -A 2 -B 2
2626
read -p "There are some occurrences of forbidden patterns at your modification. Are you sure want to continue? (y/n)" yn
2727
echo $yn | grep ^[Yy]$
28-
if [ $? -eq 0 ]
29-
then
30-
exit 0; #THE USER WANTS TO CONTINUE
31-
else
28+
if [ $? -ne 0 ]; then
3229
exit 1; # THE USER DONT WANT TO CONTINUE SO ROLLBACK
3330
fi
3431
else
3532
echo -e "\033[1;31mWARNING: Some occurences of forbidden patterns were detected \033[0m"
3633
exec git diff --cached --color | grep -nE $consoleregexp -A 2 -B 2
3734
fi
3835
fi
36+
37+
# Css wrap check
38+
node .husky/scss_check.js
3939
fi

.husky/scss_check.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { execSync } from "child_process";
2+
import { existsSync, readFileSync } from "fs";
3+
import process from "process";
4+
5+
const commentPattern = /\/\/.*|\/\*[\s\S]*?\*\//g;
6+
// const firstLevelSelectorPattern = /^(\.(?!o-spreadsheet\s)|[a-zA-Z]+).*\{/gm;
7+
const firstLevelSelectorPattern = /^(?!(\s|\$|\})).+/gm;
8+
9+
// Get scss files in diff
10+
const files = execSync("git diff --name-only --cached")
11+
.toString()
12+
.split("\n")
13+
.filter((file) => file.endsWith(".scss"));
14+
15+
const faultyFiles = [];
16+
17+
for (const file of files) {
18+
if (!existsSync(file)) continue;
19+
let content = readFileSync(file, "utf8");
20+
21+
// Remove content of comments
22+
content = content.replace(commentPattern, "");
23+
// look for first level selectors
24+
const firstLevelSelectors = content.match(firstLevelSelectorPattern);
25+
if (!firstLevelSelectors.every((line) => line.startsWith(".o-spreadsheet "))) {
26+
faultyFiles.push(file);
27+
}
28+
}
29+
30+
if (faultyFiles.length > 0) {
31+
const fileList = " - " + faultyFiles.join("\n - ");
32+
console.log(`\x1b[31m
33+
Some scss files are not scoped to .o-spreadsheet. Please fix them before committing.
34+
Faulty files:
35+
36+
${fileList}
37+
38+
Your file should start with:
39+
.o-spreadsheet {
40+
...
41+
}
42+
43+
and the selector should encompass all the style.\x1b[0m
44+
`);
45+
process.exit(1);
46+
}

src/variables.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
$os-text-body: #374151;
1+
$os-text-body: #1869eb;

0 commit comments

Comments
 (0)