Skip to content

Commit c67515e

Browse files
author
Maksim Sadym
committed
Check no break lines in blocks
1 parent b3e6a24 commit c67515e

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

scripts/formatter/no_split_var.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env node
2+
3+
const fs = require('fs')
4+
const path = require('path')
5+
const specPath = path.resolve(__dirname, '..', '..', 'index.bs')
6+
const specLines = fs.readFileSync(specPath, 'utf-8')
7+
.toString()
8+
.split('\n');
9+
10+
let failed = [];
11+
const openClosePairs = [["[=", "=]"], ["<dfn", "</dfn"], ["<var", "</var"], ["[", "]"], ["<code", "</code"]];
12+
13+
for (let i = 0; i < specLines.length; i++) {
14+
const line = specLines[i];
15+
for (let pair of openClosePairs) {
16+
if (line.lastIndexOf(pair[0]) > line.lastIndexOf(pair[1])) {
17+
failed.push(
18+
`Unclosed ${line.substring(line.lastIndexOf(pair[0]))} at line ${i
19+
+ 1}`)
20+
}
21+
}
22+
23+
if ((line.split("|") - 1).length % 2) {
24+
failed.push(
25+
`Unclosed ${line.substring(line.lastIndexOf("|"))} at line ${i + 1}`)
26+
}
27+
}
28+
29+
if (failed.length > 0) {
30+
throw new Error(`${failed.length} errors found:\n${failed.join("\n")}`);
31+
}

scripts/test.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@ $ROOT/scripts/cddl/generate.js
1919

2020
cddl compile-cddl --cddl local.cddl
2121
cddl compile-cddl --cddl remote.cddl
22+
23+
# Check break lines inside blocks.
24+
$ROOT/scripts/formatter/no_split_var.js

0 commit comments

Comments
 (0)