Skip to content

Commit 825ed0e

Browse files
authored
chore(ws): added cspell to enforce spelling check (#469)
Signed-off-by: paulovmr <[email protected]>
1 parent cbedbff commit 825ed0e

File tree

13 files changed

+1093
-70
lines changed

13 files changed

+1093
-70
lines changed

workspaces/frontend/.eslintrc.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ module.exports = {
2323
'no-relative-import-paths',
2424
'prettier',
2525
'local-rules',
26+
'@cspell',
2627
],
2728
extends: [
2829
'eslint:recommended',
@@ -233,6 +234,10 @@ module.exports = {
233234
'func-names': 'warn',
234235
'local-rules/no-react-hook-namespace': 'error',
235236
'local-rules/no-raw-react-router-hook': 'error',
237+
'@cspell/spellchecker': [
238+
'error',
239+
{ configFile: 'config/cspell.json', customWordListFile: 'config/cspell-ignore-words.txt' },
240+
],
236241
},
237242
overrides: [
238243
{
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
scipy
2+
kubeflow
3+
mochawesome
4+
jovyan
5+
millicores
6+
workspacekind
7+
workspacekinds
8+
healthcheck
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Workaround suggested in https://github.com/streetsidesoftware/cspell/issues/3215
3+
* while the fix for the library is in progress
4+
*/
5+
6+
const fs = require('fs');
7+
const path = require('path');
8+
9+
/**
10+
* Search for `package.json`
11+
* @param {string} from - search `from` directory.
12+
* @returns {string} - path to package.json
13+
*/
14+
function findNearestPackageJson(from) {
15+
from = path.resolve(from);
16+
const parent = path.dirname(from);
17+
if (!from || parent === from) {
18+
return;
19+
}
20+
21+
const pkg = path.join(from, 'package.json');
22+
if (fs.existsSync(pkg)) {
23+
return pkg;
24+
}
25+
return findNearestPackageJson(parent);
26+
}
27+
28+
/**
29+
* Load the nearest package.json
30+
* @param {string} cwd
31+
* @returns
32+
*/
33+
function loadPackage(cwd) {
34+
const pkgFile = findNearestPackageJson(cwd);
35+
if (!pkgFile) return;
36+
return JSON.parse(fs.readFileSync(pkgFile, 'utf-8'));
37+
}
38+
39+
function determinePackageNamesAndMethods(cwd = process.cwd()) {
40+
const pkg = loadPackage(cwd) || {};
41+
const packageNames = Object.keys(pkg.dependencies || {}).concat(
42+
Object.keys(pkg.devDependencies || {}),
43+
);
44+
const setOfWords = new Set(packageNames.flatMap((name) => name.replace(/[@]/g, '').split('/')));
45+
const words = [...setOfWords];
46+
return { words };
47+
}
48+
49+
module.exports = {
50+
words: determinePackageNamesAndMethods().words,
51+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"import": ["./cspell.config.cjs"]
3+
}

0 commit comments

Comments
 (0)