@entva/styleguide 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ci.yml +14 -0
- package/LICENSE +21 -0
- package/README.md +88 -0
- package/css/README.md +385 -0
- package/css/packages/stylelint/LICENSE +21 -0
- package/css/packages/stylelint/README.md +27 -0
- package/css/packages/stylelint/eslint.config.js +3 -0
- package/css/packages/stylelint/index.js +84 -0
- package/css/packages/stylelint/package-lock.json +4042 -0
- package/css/packages/stylelint/package.json +42 -0
- package/html/README.md +98 -0
- package/javascript/README.md +3255 -0
- package/javascript/packages/eslint-base/LICENSE +21 -0
- package/javascript/packages/eslint-base/README.md +27 -0
- package/javascript/packages/eslint-base/eslint.config.js +3 -0
- package/javascript/packages/eslint-base/index.js +1084 -0
- package/javascript/packages/eslint-base/package-lock.json +2653 -0
- package/javascript/packages/eslint-base/package.json +36 -0
- package/javascript/packages/eslint-react/LICENSE +21 -0
- package/javascript/packages/eslint-react/README.md +27 -0
- package/javascript/packages/eslint-react/eslint.config.js +3 -0
- package/javascript/packages/eslint-react/index.js +526 -0
- package/javascript/packages/eslint-react/package-lock.json +3035 -0
- package/javascript/packages/eslint-react/package.json +42 -0
- package/package.json +15 -0
- package/react/README.md +726 -0
- package/scripts/for-each-package +12 -0
- package/test/css.js +36 -0
- package/test/index.js +7 -0
- package/test/js.js +35 -0
- package/test/utils.js +63 -0
- package/tooling/packages/biome/LICENSE +21 -0
- package/tooling/packages/biome/README.md +27 -0
- package/tooling/packages/biome/biome.json +1285 -0
- package/tooling/packages/biome/package-lock.json +183 -0
- package/tooling/packages/biome/package.json +38 -0
- package/tsconfig.json +31 -0
- package/typescript/README.md +66 -0
- package/typescript/packages/eslint-typescript-base/LICENSE +21 -0
- package/typescript/packages/eslint-typescript-base/README.md +27 -0
- package/typescript/packages/eslint-typescript-base/eslint.config.js +3 -0
- package/typescript/packages/eslint-typescript-base/index.js +272 -0
- package/typescript/packages/eslint-typescript-base/package-lock.json +3215 -0
- package/typescript/packages/eslint-typescript-base/package.json +41 -0
- package/typescript/packages/eslint-typescript-base/tsconfig.json +30 -0
- package/typescript/packages/eslint-typescript-react/LICENSE +21 -0
- package/typescript/packages/eslint-typescript-react/README.md +27 -0
- package/typescript/packages/eslint-typescript-react/eslint.config.js +3 -0
- package/typescript/packages/eslint-typescript-react/index.js +75 -0
- package/typescript/packages/eslint-typescript-react/package-lock.json +3630 -0
- package/typescript/packages/eslint-typescript-react/package.json +41 -0
- package/typescript/packages/eslint-typescript-react/tsconfig.json +30 -0
package/test/css.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { resolve } from 'path';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import { collectLinterErrors, createTestErrorsCollector } from './utils.js';
|
|
4
|
+
|
|
5
|
+
// ESM is very convenient and doesn't require any workarounds for the CJS dynamic import
|
|
6
|
+
const loadStyleLint = async () => {
|
|
7
|
+
const cwd = process.cwd();
|
|
8
|
+
const pkg = JSON.parse(fs.readFileSync(resolve(cwd, 'node_modules/stylelint/package.json'), 'utf8'));
|
|
9
|
+
const styleLint = resolve(cwd, 'node_modules/stylelint', pkg.main);
|
|
10
|
+
const mod = await import(styleLint);
|
|
11
|
+
return mod.default;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
const processFile = (result) => {
|
|
16
|
+
const errorsLinter = result.warnings.reduce(collectLinterErrors, []);
|
|
17
|
+
const errorsTest = errorsLinter.reduce(createTestErrorsCollector(result.source), []);
|
|
18
|
+
|
|
19
|
+
if (errorsTest.length) throw `Errors found:\n${errorsTest.join('\n')}`;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const run = async (dir, exts = 'css,scss') => {
|
|
23
|
+
const stylelint = await loadStyleLint();
|
|
24
|
+
try {
|
|
25
|
+
const report = await stylelint.lint({
|
|
26
|
+
files: exts.split(',').map((ext) => `${dir}/**/*.${ext}`),
|
|
27
|
+
quietDeprecationWarnings: true,
|
|
28
|
+
});
|
|
29
|
+
report.results.forEach(processFile);
|
|
30
|
+
} catch (err) {
|
|
31
|
+
console.error(err);
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export default run;
|
package/test/index.js
ADDED
package/test/js.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { resolve } from 'path';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import { collectLinterErrors, createTestErrorsCollector } from './utils.js';
|
|
4
|
+
|
|
5
|
+
// ESM is very convenient and doesn't require any workarounds for the CJS dynamic import
|
|
6
|
+
const loadESLint = async () => {
|
|
7
|
+
const cwd = process.cwd();
|
|
8
|
+
const pkg = JSON.parse(fs.readFileSync(resolve(cwd, 'node_modules/eslint/package.json'), 'utf8'));
|
|
9
|
+
const eslintPath = resolve(cwd, 'node_modules/eslint', pkg.main);
|
|
10
|
+
return import(eslintPath);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const processFile = (file) => {
|
|
14
|
+
const errorsLinter = file.messages.reduce(collectLinterErrors, []);
|
|
15
|
+
const errorsTest = errorsLinter.reduce(createTestErrorsCollector(file.filePath), []);
|
|
16
|
+
|
|
17
|
+
if (errorsTest.length) {
|
|
18
|
+
console.error(`Errors found:\n${errorsTest.join('\n')}`);
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return true;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const run = async (dir, ext = 'js') => {
|
|
26
|
+
const { ESLint } = await loadESLint();
|
|
27
|
+
const eslint = new ESLint({ overrideConfigFile: resolve(process.cwd(), 'index.js') });
|
|
28
|
+
const result = await eslint.lintFiles(`${dir}/**/*.${ext}`);
|
|
29
|
+
|
|
30
|
+
const isSuccess = result.map(processFile).every(r => r);
|
|
31
|
+
|
|
32
|
+
process.exit(isSuccess ? 0 : 1)
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export default run;
|
package/test/utils.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { readFileSync } from 'fs';
|
|
2
|
+
import { relative } from 'path';
|
|
3
|
+
|
|
4
|
+
const specPrefix = '// expect:';
|
|
5
|
+
|
|
6
|
+
const arrayDiff = (arr, compareArr) => arr.filter((err) => !compareArr.includes(err));
|
|
7
|
+
const formatError = (filePath, line, message) => (
|
|
8
|
+
`[${relative(process.cwd(), filePath)}:${line}] ${message}`
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
const parseSpec = (spec) => {
|
|
12
|
+
if (!spec || !spec.includes(specPrefix)) return [];
|
|
13
|
+
|
|
14
|
+
const rules = spec.replace(specPrefix, '');
|
|
15
|
+
return rules.split(',').map((rule) => rule.trim());
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const findSpecLineIndex = (line, fileLines) => {
|
|
19
|
+
const mayBeFileError = line === 1;
|
|
20
|
+
if (mayBeFileError) return 0;
|
|
21
|
+
|
|
22
|
+
for (let i = line - 2; i >= 0; i -= 1) {
|
|
23
|
+
if (!fileLines[i].trim()) continue;
|
|
24
|
+
return i;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return line - 2;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const collectLinterErrors = (acc, { line, ruleId, rule }) => {
|
|
31
|
+
const lineRecord = acc.find((item) => item.line === line);
|
|
32
|
+
const ruleKey = ruleId || rule;
|
|
33
|
+
|
|
34
|
+
if (lineRecord) {
|
|
35
|
+
lineRecord.rules.push(ruleKey);
|
|
36
|
+
} else {
|
|
37
|
+
acc.push({ line, rules: [ruleKey] });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return acc;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const createTestErrorsCollector = (filePath) => {
|
|
44
|
+
const fileLines = readFileSync(filePath, 'utf8').split('\n');
|
|
45
|
+
|
|
46
|
+
return (acc, { line, rules }) => {
|
|
47
|
+
const specLineIndex = findSpecLineIndex(line, fileLines);
|
|
48
|
+
const specRules = parseSpec(fileLines[specLineIndex]);
|
|
49
|
+
|
|
50
|
+
const notCheckedRules = arrayDiff(specRules, rules);
|
|
51
|
+
const extraCheckedRules = arrayDiff(rules, specRules);
|
|
52
|
+
|
|
53
|
+
if (notCheckedRules.length) {
|
|
54
|
+
acc.push(formatError(filePath, line, `Linter should check these rules: ${notCheckedRules.join(', ')}`));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (extraCheckedRules.length) {
|
|
58
|
+
acc.push(formatError(filePath, line, `Linter should not check these rules: ${extraCheckedRules.join(', ')}`));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return acc;
|
|
62
|
+
};
|
|
63
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) Maxim Degterev <max@degterev.me> (https://max.degterev.me)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# eslint-config-entva-typescript
|
|
2
|
+
|
|
3
|
+
> Shareable entva typescript styleguide config for eslint.
|
|
4
|
+
|
|
5
|
+
Extends [`eslint-config-airbnb-typescript`](https://github.com/iamturns/eslint-config-airbnb-typescript).
|
|
6
|
+
|
|
7
|
+
A shareable config to enforce entva styleguide: https://github.com/entva/styleguide
|
|
8
|
+
|
|
9
|
+
To see the rules that this config uses, please read the [config itself](./index.js).
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install eslint-config-entva-typescript --save-dev
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
If you've installed `eslint-config-entva-typescript` locally within your project, just set your `eslint` config to:
|
|
20
|
+
|
|
21
|
+
```json
|
|
22
|
+
{
|
|
23
|
+
"extends": "eslint-config-entva-typescript"
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## [MIT License](LICENSE)
|