feat: TechDocs - Add vale linter to check words quality in md files. (#2631)
* fix(docs): typos which were reflacted from vale linter's command * feat: Implement Vale linter (#2031) Initialize .vale.ini file Add 'lint:docs' script to package.json, to lint all md files except the ones which are located in node_modules Generate 'vocab.txt' by using command 'yarn run lint:docs' | grep -o ''[a-z A-Z]*'' | grep -o '[a-z A-Z]*' | sort | uniq > .github/styles/vocab.txt Add steps to github workflow 'master' to check docs quality * chore: Separate workflow for quality checking * chore: Added 'shx' dev dependency to support grep command in cross platform * feat: Add script to operate same quality check process on different platform * ignore: remove lint:docs from lint-stages which was added for experiment purpose * fix: check-all-files on push event & check-changed-files on pull_request event * chore(CI): triggle workflow only when there is any updates in .md file(s) on pull request * fix: use spawnSync to solve 'The command line is too long.' error * fix: github workflow syntax * fix: prettier error * chore: add vale command directly to lint-staged * chore: use shebang for easy access * fix: windows script issue & remove shebang * chore: Add shebang flag * chore: better error message related to vale * chore: mention vale linter in documentation * fix: spelling errors & add keywords to vocab.txt
This commit is contained in:
committed by
GitHub
parent
73440c7d9a
commit
5c6a0356c0
Executable
+68
@@ -0,0 +1,68 @@
|
||||
#!/usr/bin/env node
|
||||
/*
|
||||
* Copyright 2020 Spotify AB
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
const { execSync, spawnSync } = require('child_process');
|
||||
const path = require('path');
|
||||
|
||||
const listFilesTrackedByGit = 'git ls-files';
|
||||
|
||||
const inheritStdIo = {
|
||||
stdio: 'inherit',
|
||||
};
|
||||
|
||||
const ERROR_MESSAGE =
|
||||
'Please install vale linter(https://docs.errata.ai/vale/install). Ignore this message if already installed.\n';
|
||||
|
||||
// xargs is not supported by shx.
|
||||
if (process.platform === 'win32') {
|
||||
const validMDFilesCommand = `${listFilesTrackedByGit} | .\\node_modules\\.bin\\shx grep ".md"`;
|
||||
try {
|
||||
// get list of all md files except in directories of gitignore.
|
||||
let filesToLint = execSync(validMDFilesCommand, {
|
||||
stdio: ['ignore', 'pipe', 'inherit'],
|
||||
});
|
||||
|
||||
// set all file(s) path as absolute path
|
||||
filesToLint = filesToLint
|
||||
.toString()
|
||||
.split('\n')
|
||||
.map(filepath => (filepath ? path.join(process.cwd(), filepath) : null))
|
||||
.filter(Boolean);
|
||||
|
||||
const output = spawnSync('vale', filesToLint, inheritStdIo);
|
||||
|
||||
// if the command does not succeed
|
||||
if (output.status !== 0) {
|
||||
// if it contains system level error. [in this case vale does not exist]
|
||||
if (output.error) {
|
||||
console.error(ERROR_MESSAGE);
|
||||
}
|
||||
process.exit(1);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
process.exit(1);
|
||||
}
|
||||
} else {
|
||||
const validMDFilesCommand = `${listFilesTrackedByGit} | ./node_modules/.bin/shx grep ".md"`;
|
||||
// use xargs
|
||||
try {
|
||||
execSync(`${validMDFilesCommand} | xargs vale`, inheritStdIo);
|
||||
} catch (e) {
|
||||
console.error(ERROR_MESSAGE);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user