Andy Stark dfc83489e2 [ADF-3093] Added style checking tool for en.json translation file (#3428)
* [ADF-3093] Started li18nt VS Code extension

* [ADF-3093] Started work on UI style lint tool for VSCode

* [ADF-3093] Added UI style rules up to sg0006

* [ADF-3093] Added remaining style rules

* [ADF-3093] Added docs and command line tool

* [ADF-3093] Removed Microsoft notices and updated licences to Apache-2.0
2018-06-05 17:49:52 +02:00

33 lines
830 B
TypeScript

import * as fs from 'fs';
import * as path from 'path';
import * as program from 'commander';
import {
SGStringProblem, sgErrorMessages, rules
} from './li18nt/server/src/SGStyleRules';
program
.usage(" <source>")
.parse(process.argv);
if (program.args.length === 0) {
console.log('Error: source file "en.json" must be provided');
process.exit();
}
let text = fs.readFileSync(path.resolve(program.args[0]), 'utf8');
let lines = text.split(/\r?\n/g);
let messages: SGStringProblem[] = [];
lines.forEach((line, index) => {
rules.forEach(rule => {
let newProblems = rule(line, index);
messages.push(...newProblems);
});
});
messages.forEach(message => {
console.log(`Line ${message.lineNum} (${message.startCharPos}-${message.endCharPos}): ${sgErrorMessages[message.messageCode]}`)
});