Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'textlint' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
testValidPattern(name: string, param: TextlintRuleModule | TestConfig, valid: TesterValid) {
const text = typeof valid === "object" ? valid.text : valid;
const inputPath = typeof valid === "object" ? valid.inputPath : undefined;
const ext = typeof valid === "object" && valid.ext !== undefined ? valid.ext : ".md";
const textlint = new TextLintCore();
if (isTestConfig(param)) {
const testRuleSet = createTestRuleSet(param.rules);
textlint.setupRules(testRuleSet.rules, testRuleSet.rulesOptions);
if (param.plugins !== undefined) {
const testPluginSet = createTestPluginSet(param.plugins);
textlint.setupPlugins(testPluginSet.plugins, testPluginSet.pluginOptions);
}
} else {
const options =
typeof valid === "object"
? valid.options
: // just enable
true;
textlint.setupRules(
{
[name]: param
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!");
}
});
}
// LICENSE : MIT
"use strict";
// run as app
var cli = require("textlint").cli;
cli
.execute(process.argv.concat(__dirname + "/md/"))
.then(function(exit) {
console.log(exit);
})
.catch(function(error) {
console.error(error);
});
// LICENSE : MIT
"use strict";
// run as app
var cli = require("textlint").cli;
cli
.execute(process.argv.concat(__dirname + "/md/"))
.then(function(exit) {
console.log(exit);
})
.catch(function(error) {
console.error(error);
});
// 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),
testInvalidPattern(name: string, param: TextlintRuleModule | TestConfig, invalid: TesterInvalid) {
const errors = invalid.errors;
const inputPath = invalid.inputPath;
const text = invalid.text;
const ext = invalid.ext !== undefined ? invalid.ext : ".md";
const textlint = new TextLintCore();
if (isTestConfig(param)) {
const testRuleSet = createTestRuleSet(param.rules);
textlint.setupRules(testRuleSet.rules, testRuleSet.rulesOptions);
if (Array.isArray(param.plugins)) {
const testPluginSet = createTestPluginSet(param.plugins);
textlint.setupPlugins(testPluginSet.plugins, testPluginSet.pluginOptions);
}
} else {
const options = invalid.options;
textlint.setupRules(
{
[name]: param
},
{
[name]: options
}
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;
}