Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function lintFile(filePath) {
/**
* See lib/_typing/textlint.d.ts
*/
var options = {
// load rules from [../rules]
rules: ["no-todo"],
formatterName: "pretty-error"
};
var engine = new TextLintEngine(options);
var filePathList = [path.resolve(process.cwd(), filePath)];
return engine.executeOnFiles(filePathList).then(function(results) {
if (engine.isErrorResults(results)) {
var output = engine.formatResults(results);
console.log(output);
} else {
console.log("All Passed!");
}
});
}
// local config
let configFile = directory.resolve('./.textlintrc');
let pluginPath = directory.resolve('./node_modules/');
if (!existsConfig(configFile, pluginPath)) {
if (!existsConfig(textlintrcPath, textlintRulesDir)) {
return Promise.resolve([]);
}
// use global config
configFile = textlintrcPath;
pluginPath = textlintRulesDir;
}
const textlint = new TextLintEngine({
configFile,
rulesBaseDirectory: pluginPath
});
const filePath = editor.getPath();
return textlint.executeOnFiles([filePath]).then((results) => {
const { push } = Array.prototype;
const messages = [];
results
.filter(result => result.messages.length)
.forEach(result => push.apply(messages, result.messages));
return messages.map((message) => {
const linterMessage = {
severity: textlint.isErrorMessage(message) ? 'error' : 'warning',
location: {
async function validateTextDocument(textDocument: TextDocument): Promise {
// In this simple example we get the settings for every validate run.
const settings = await getDocumentSettings(textDocument.uri);
const document = textDocument.getText();
const ext: string = path.extname(
vscode_uri.default.parse(textDocument.uri).fsPath,
);
const engine: TextLintEngine = new TextLintEngine({
configFile: path.resolve(__dirname, "../.textlintrc"),
});
const results: TextlintResult[] = await engine.executeOnText(document, ext);
const diagnostics: Diagnostic[] = [];
if (engine.isErrorResults(results)) {
const messages: TextlintMessage[] = results[0].messages;
const l: number = messages.length;
for (let i: number = 0; i < l; i++) {
const message: TextlintMessage = messages[i];
const text: string = message.message;
const pos: Position = Position.create(
Math.max(0, message.line - 1),
Math.max(0, message.column - 1),
module.exports = function(options) {
options = options || {};
const textlint = new TextLintEngine(options);
const filePaths = [];
return through.obj(
function(file, enc, cb) {
filePaths.push(file.path);
this.push(file);
cb();
},
function(cb) {
const that = this;
textlint
.executeOnFiles(filePaths)
.then(function(results) {
if (textlint.isErrorResults(results)) {
log(textlint.formatResults(results));
that.emit("error", new PluginError("textlint", "Lint failed."));
module.exports = function lintFiles (input, options) {
const config = createConfig(options)
const patterns = input.length === 0 ? ['**/*.md'] : input
const engine = options.fix
? new textlint.TextFixEngine(config)
: new textlint.TextLintEngine(config)
return globby(patterns, {gitignore: true})
.then(paths => engine.executeOnFiles(paths))
.then(results => {
if (!options.fix) {
return results
}
const fixer = new TextLintFixer()
return fixer.write(results).then(() => results)
})
}
get lintEngine() {
if (this._textLintEngine) {
return this._textLintEngine;
}
const textLineEngine = new textlint.TextLintEngine({
configFile: this.configFile,
rulesBaseDirectory: this.rulesBaseDirectory
});
this._textLintEngine = textLineEngine;
return textLineEngine;
}