Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ This is a repository that contains the OpenRPC specification, and the tooling to

## Latest OpenRPC Specification

The latest version of the specification may be found [here](https://spec.open-rpc.org/).
The latest version of the specification can be found [here](https://spec.open-rpc.org/).

## Previous Versions of the Specification

All versions of the specification can be found on [the Github releases page](https://github.com/open-rpc/spec/releases).

You may also access specific versions of the spec by appending the version to the spec url as follows:
You can also access specific versions of the spec by appending the version to the spec url as follows:

`https://spec.open-rpc.org/1.0.0`

Expand Down
59 changes: 59 additions & 0 deletions bin/rfc2119.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env node
const fs = require('fs');

const phrases = [
'MUST',
'MUST NOT',
'REQUIRED',
'SHALL',
'SHALL NOT',
'SHOULD',
'SHOULD NOT',
'RECOMMENDED',
'NOT RECOMMENDED',
'MAY',
'OPTIONAL'
];

// Build regex pattern
const pattern = new RegExp(`\\b(${phrases.map(p => p.replace(/ /g, '\\s+')).join('|')})\\b`, 'gi');

const files = process.argv.slice(2);
if (files.length === 0) {
console.error('No files specified.');
process.exit(1);
}

let hasErrors = false;

for (const file of files) {
if (!fs.existsSync(file)) {
// Skip nonexistent files (e.g., glob patterns with no matches)
continue;
}
const content = fs.readFileSync(file, 'utf8').split(/\r?\n/);
content.forEach((line, idx) => {
let text = line;
// Remove inline code blocks
text = text.replace(/`[^`]*`/g, '');
// If line is a table, ignore first column
if (text.includes('|')) {
text = text.split('|').slice(1).join('|');
}
let match;
while ((match = pattern.exec(text)) !== null) {
const found = match[0];
const normalized = found.replace(/\s+/g, ' ');
const expected = phrases.find(p => p.toLowerCase() === normalized.toLowerCase());
if (found !== expected) {
const col = match.index + 1;
console.warn(`${file}:${idx + 1}:${col} RFC2119 keyword should be "${expected}" but found "${found}"`);
hasErrors = true;
}
}
});
}

if (hasErrors) {
process.exit(1);
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"private": true,
"scripts": {
"validate": "node_modules/.bin/mdv ./spec.md ./README.md ./build/markdown/*.md",
"lint": "./node_modules/.bin/markdownlint ./spec.md ./README.md ./build/markdown/*.md",
"lint": "node ./bin/rfc2119.js ./spec.md ./README.md ./build/markdown/*.md && ./node_modules/.bin/markdownlint ./spec.md ./README.md ./build/markdown/*.md",
"build": "./bin/build.sh",
"test": "npm run build && npm run validate && npm run lint"
},
Expand Down
Loading