c3b-lint 0.0.20 → 0.0.21
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/README.md +5 -2
- package/c3b-lint.js +9 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,7 +21,9 @@ markdown that a tool can check, with one command and one config to install. It r
|
|
|
21
21
|
rules (that is a token by definition), and a token nothing uses (CSS `var()`, or JS/HTML by name).
|
|
22
22
|
4. That the project's **`.editorconfig`** is the shared one — it carries the JetBrains `ij_*` code-style keys, so
|
|
23
23
|
WebStorm and IntelliJ format the same way without committing `.idea/`.
|
|
24
|
-
5. The **500-line limit** on `src/**/*.{css,html}` (ESLint reports the JS); inline `<svg>` art is not counted
|
|
24
|
+
5. The **500-line limit** on `src/**/*.{css,html}` (ESLint reports the JS); inline `<svg>` art is not counted, nor is
|
|
25
|
+
a [colab-partial](https://codeberg.org/colab47/colab-partial) region whose partial is in `src/partial/` (one line
|
|
26
|
+
each: the partial is counted on its own).
|
|
25
27
|
6. **ESLint** on every `.js` file — classic browser scripts under `src/` (IIFE required, no top-level declarations,
|
|
26
28
|
no `console.log`), ES modules everywhere else — with `eslint:recommended` plus the rules from `frontend.md`:
|
|
27
29
|
braces on every `if`, `const`/`let` never `var`, `===`, a blank line before `return`, 500 lines max, and a
|
|
@@ -85,7 +87,8 @@ A project's own settings go in its `package.json`, under `"c3b-lint"`:
|
|
|
85
87
|
its own and never reads the HTML, so without them every use is "not defined". Read-only, `src/` scripts only.
|
|
86
88
|
- `singularDirectories` — plural-looking directory names that are proper names (a client's brand).
|
|
87
89
|
- `ignoreLength` — globs exempt from the 500-line limit and nothing else: the HTML, token, structure, ESLint and
|
|
88
|
-
Stylelint checks still run on them. For a file that can't be split
|
|
90
|
+
Stylelint checks still run on them. For a file that can't be split. A page made long by the partials it carries
|
|
91
|
+
needs none: their regions count as one line each.
|
|
89
92
|
|
|
90
93
|
The ESLint and Stylelint configs read these too, so WebStorm reports what the CLI does.
|
|
91
94
|
|
package/c3b-lint.js
CHANGED
|
@@ -131,14 +131,21 @@ function checkEditorconfig(report) {
|
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
+
// A colab-partial region: the opening marker's line, the copy, the closing marker's line naming the same partial
|
|
135
|
+
const PARTIAL_REGION = /^[ \t]*<!-- partial ([\w./-]+) -->[ \t]*\r?\n[\s\S]*?^[ \t]*<!-- \/partial \1 -->/gm;
|
|
136
|
+
|
|
134
137
|
// general.md: no hand-written file past 500 lines. ESLint reports JS; this covers CSS and HTML.
|
|
135
138
|
function checkFileLengths(report) {
|
|
136
139
|
const ignored = ignoredPaths();
|
|
137
140
|
const exempt = ignoredPaths(readSettings().ignoreLength);
|
|
138
141
|
const files = globSync('src/**/*.{css,html}').map(toPosix).filter((file) => !file.includes('/vendor/') && !ignored.has(file) && !exempt.has(file));
|
|
139
142
|
for (const file of files.sort()) {
|
|
140
|
-
// inline <svg> is vector art, not hand-written markup: its lines are not counted
|
|
141
|
-
|
|
143
|
+
// inline <svg> is vector art, not hand-written markup: its lines are not counted. Nor is a partial's
|
|
144
|
+
// copy (colab-partial writes it from src/partial/, which is counted on its own): one line, as long as
|
|
145
|
+
// that partial is there, so markers can't hide markup written nowhere else
|
|
146
|
+
const content = readFileSync(file, 'utf8')
|
|
147
|
+
.replace(/<svg[\s\S]*?<\/svg>/g, '<svg/>')
|
|
148
|
+
.replace(PARTIAL_REGION, (region, name) => (existsSync(join('src', 'partial', name)) ? `<!-- partial ${ name } -->` : region));
|
|
142
149
|
const lines = content.split('\n').length - (content.endsWith('\n') ? 1 : 0);
|
|
143
150
|
if (lines > MAX_LINES) {
|
|
144
151
|
report.error(file, `is ${ lines } lines (limit ${ MAX_LINES }) — split it by responsibility`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "c3b-lint",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.21",
|
|
4
4
|
"description": "Lints a co:lab project against the rules a tool can check: ESLint, Stylelint, the 500-line limit and the shared .editorconfig; --init writes the config files.",
|
|
5
5
|
"license": "GPL-3.0",
|
|
6
6
|
"type": "module",
|