c3b-lint 0.0.7 → 0.0.8
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 +2 -2
- package/c3b-lint.js +2 -1
- package/check/css-tokens.js +5 -0
- package/check/html.js +6 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ markdown that a tool can check, with one command and one config to install. It r
|
|
|
15
15
|
rules (that is a token by definition), and a token nothing uses (CSS `var()`, or JS/HTML by name).
|
|
16
16
|
4. **HTML** on every page under `src/` (partials are skipped): doctype, `lang`, charset, viewport without
|
|
17
17
|
`user-scalable=no`, the required head set (title, description, absolute canonical, `og:*` with an absolute
|
|
18
|
-
`og:image`, `twitter:card`, one SVG favicon; a `noindex` page is excused the canonical and social tags), stylesheet order (`reset`, `tokens`, `main`, …, page file last),
|
|
18
|
+
`og:image`, `twitter:card`, one SVG favicon; a `noindex` page is excused the canonical and social tags), no external stylesheets (webfonts are self-hosted), stylesheet order (`reset`, `tokens`, `main`, …, page file last),
|
|
19
19
|
the skip-link rule (`<a id="skip-link" href="#main">` first in `<body>` when there is a header or nav, absent
|
|
20
20
|
otherwise, `<main id="main">`), one `<h1>`, `alt` on every image, no inline handlers, no `<style>` or `style=""`
|
|
21
21
|
(except a JS-driven custom property), relative paths only, kebab-case ids and classes, no duplicate ids,
|
|
@@ -25,7 +25,7 @@ markdown that a tool can check, with one command and one config to install. It r
|
|
|
25
25
|
(an experiment under `src/experiment/<name>/` keeps its own beside its `index.html`), fonts only in
|
|
26
26
|
`src/asset/font/` as woff2, file names starting with a letter. A directory whose plural-looking name is a proper
|
|
27
27
|
name (a client's brand) is listed in `package.json` under `"c3b-lint": { "singularDirectories": [...] }`.
|
|
28
|
-
6. The **500-line limit** on `src/**/*.{css,html}` (ESLint reports the JS).
|
|
28
|
+
6. The **500-line limit** on `src/**/*.{css,html}` (ESLint reports the JS); inline `<svg>` art is not counted.
|
|
29
29
|
7. That the project's **`.editorconfig`** is the shared one — it carries the JetBrains `ij_*` code-style keys, so
|
|
30
30
|
WebStorm and IntelliJ format the same way without committing `.idea/`.
|
|
31
31
|
|
package/c3b-lint.js
CHANGED
|
@@ -129,7 +129,8 @@ function checkFileLengths() {
|
|
|
129
129
|
let errors = 0;
|
|
130
130
|
const files = globSync('src/**/*.{css,html}').filter((file) => !toPosix(file).includes('/vendor/'));
|
|
131
131
|
for (const file of files.sort()) {
|
|
132
|
-
|
|
132
|
+
// inline <svg> is vector art, not hand-written markup: its lines are not counted
|
|
133
|
+
const content = readFileSync(file, 'utf8').replace(/<svg[\s\S]*?<\/svg>/g, '<svg/>');
|
|
133
134
|
const lines = content.split('\n').length - (content.endsWith('\n') ? 1 : 0);
|
|
134
135
|
if (lines > MAX_LINES) {
|
|
135
136
|
console.log(` error ${ toPosix(file) } is ${ lines } lines (limit ${ MAX_LINES }) — split it by responsibility`);
|
package/check/css-tokens.js
CHANGED
|
@@ -40,6 +40,11 @@ function readTokens() {
|
|
|
40
40
|
return tokens;
|
|
41
41
|
}
|
|
42
42
|
root.walkDecls(/^--/, (decl) => {
|
|
43
|
+
// the base definition only: a media-query override of a token is a different value for the
|
|
44
|
+
// same role, not a second token with that value
|
|
45
|
+
if (decl.parent.parent?.type === 'atrule' || tokens.has(decl.prop)) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
43
48
|
tokens.set(decl.prop, normalise(decl.value));
|
|
44
49
|
});
|
|
45
50
|
|
package/check/html.js
CHANGED
|
@@ -111,8 +111,13 @@ function checkPage(report, file, source) {
|
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
// --- stylesheet link order: reset, tokens, main, components, page file last
|
|
114
|
-
const
|
|
114
|
+
const allSheets = headEls.filter((el) => el.name === 'link' && attr(el, 'rel') === 'stylesheet')
|
|
115
115
|
.map((el) => ({ el, href: attr(el, 'href') ?? '' }));
|
|
116
|
+
// frontend.md: webfonts are self-hosted woff2 in src/asset/font/; no stylesheet comes from another origin
|
|
117
|
+
for (const sheet of allSheets.filter((s) => /^(https?:)?\/\//.test(s.href))) {
|
|
118
|
+
report.error(at(sheet.el), `external stylesheet ${ sheet.href } — self-host it (fonts as woff2 in src/asset/font/)`);
|
|
119
|
+
}
|
|
120
|
+
const sheets = allSheets.filter((s) => !/^(https?:)?\/\//.test(s.href));
|
|
116
121
|
const names = sheets.map((s) => basename(s.href.split('?')[0]));
|
|
117
122
|
const expectedStart = STYLE_ORDER.filter((n) => names.includes(n));
|
|
118
123
|
if (names.slice(0, expectedStart.length).join() !== expectedStart.join()) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "c3b-lint",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
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",
|