@wix/origami-lint 1.34.2 → 1.34.3
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/dist/lint.js +6 -2
- package/dist/project-model/index.js +2 -0
- package/dist/project-model/project-model.js +15 -0
- package/dist/project-rules-runner/index.js +3 -0
- package/dist/project-rules-runner/run-project-rules.js +44 -0
- package/dist/rules/project/define-project-rule.js +4 -0
- package/dist/rules/project/index.js +2 -0
- package/package.json +2 -2
package/dist/lint.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// Origami lint: lints the pages whose files changed since the last
|
|
2
|
+
// Origami lint: runs the project rules on the site's own files, then lints the pages whose files changed since the last
|
|
3
|
+
// passing run. See lint/README.md.
|
|
3
4
|
import { getChangedFiles, markPassing } from "./history/index.js";
|
|
4
5
|
import { runRules } from "./rules-adapter/index.js";
|
|
5
6
|
import { findPagesToLint } from "./page-model/index.js";
|
|
7
|
+
import { runProjectRules } from "./project-rules-runner/index.js";
|
|
6
8
|
import { checkStartedAtSiteRoot } from "./shared/paths.js";
|
|
7
9
|
checkStartedAtSiteRoot();
|
|
8
10
|
const changedFiles = getChangedFiles();
|
|
11
|
+
const projectPassed = runProjectRules(changedFiles.all);
|
|
9
12
|
const pagesToLint = findPagesToLint(changedFiles);
|
|
10
|
-
const
|
|
13
|
+
const pagesPassed = runRules(pagesToLint);
|
|
14
|
+
const passed = projectPassed && pagesPassed;
|
|
11
15
|
if (passed)
|
|
12
16
|
markPassing(changedFiles);
|
|
13
17
|
process.exit(passed ? 0 : 1);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** A path from the site root that stays inside the site: no leading /, no .. segment. */
|
|
2
|
+
function isSitePath(file) {
|
|
3
|
+
return !file.startsWith('/') && !file.split('/').includes('..');
|
|
4
|
+
}
|
|
5
|
+
/** The rule's view of the site: its files, and readFile. ruleName names the rule in readFile's error. */
|
|
6
|
+
export function createProjectModel(ruleName, files, readFile) {
|
|
7
|
+
return {
|
|
8
|
+
files,
|
|
9
|
+
readFile(file) {
|
|
10
|
+
if (!isSitePath(file))
|
|
11
|
+
throw new Error(`project rule ${ruleName} read ${file}: write a path from the site root, without ..`);
|
|
12
|
+
return readFile(file);
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Runs every project rule, on every run, on the whole site; prints each problem in the line shape the page rules'
|
|
2
|
+
// problems print in.
|
|
3
|
+
import { readFileSync } from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { projectRuleRegistry } from "../rules/project/index.js";
|
|
6
|
+
import { log } from "../shared/log.js";
|
|
7
|
+
import { ROOT } from "../shared/paths.js";
|
|
8
|
+
import { createProjectModel } from "../project-model/index.js";
|
|
9
|
+
/** true when no error rule reported a problem, on the site of these files. Logs how many rules run, and whether they passed. */
|
|
10
|
+
export function runProjectRules(files, { rules = projectRuleRegistry, readFile = readFromSite, print = console.log } = {}) {
|
|
11
|
+
log(`${rules.length} project rules to run`);
|
|
12
|
+
let passed = true;
|
|
13
|
+
for (const rule of rules) {
|
|
14
|
+
let problems;
|
|
15
|
+
try {
|
|
16
|
+
problems = rule.check(createProjectModel(rule.name, files, readFile));
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
// A rule that couldn't finish (a file it can't parse, a path out of the site) fails the run, whatever its severity.
|
|
20
|
+
print(formatProblem({ name: rule.name }, { file: '.', message: `the rule couldn't finish, so this run can't pass: ${error instanceof Error ? error.message : String(error)}` }));
|
|
21
|
+
passed = false;
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
for (const problem of problems) {
|
|
25
|
+
print(formatProblem(rule, problem));
|
|
26
|
+
if ((rule.severity ?? 'error') === 'error')
|
|
27
|
+
passed = false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
log(passed ? 'project rules passed' : 'project rules failed');
|
|
31
|
+
return passed;
|
|
32
|
+
}
|
|
33
|
+
/** `file:line:1: error origami(name): message`, the shape oxlint prints the page rules' problems in. */
|
|
34
|
+
export function formatProblem({ name, severity = 'error' }, { file, line = 1, message }) {
|
|
35
|
+
return `${file}:${line}:1: ${severity === 'error' ? 'error' : 'warning'} origami(${name}): ${message}`;
|
|
36
|
+
}
|
|
37
|
+
function readFromSite(file) {
|
|
38
|
+
try {
|
|
39
|
+
return readFileSync(path.join(ROOT, file), 'utf8');
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/origami-lint",
|
|
3
|
-
"version": "1.34.
|
|
3
|
+
"version": "1.34.3",
|
|
4
4
|
"description": "Offline lint for an exported Origami site: lints the pages that changed since the last passing run",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
]
|
|
52
52
|
}
|
|
53
53
|
},
|
|
54
|
-
"falconPackageHash": "
|
|
54
|
+
"falconPackageHash": "162134940d5c0140fe1b81ff9111d25a7f98f0201dfbbc32130245ca"
|
|
55
55
|
}
|