Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@textlint/kernel

Package Overview
Dependencies
Maintainers
3
Versions
103
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@textlint/kernel - npm Package Compare versions

Comparing version 2.0.9 to 2.1.0-alpha.0f2fd6f9

lib/kernel/src/descriptor/Descriptor.d.ts

1

lib/kernel/src/core/filter-rule-context.d.ts

@@ -26,2 +26,3 @@ import SourceCode from "./source-code";

}
export declare const createFreezedFilterRuleContext: (args: FilterRuleContextArgs) => Readonly<FilterRuleContext>;
/**

@@ -28,0 +29,0 @@ * Rule context object is passed to each rule as `context`

@@ -6,2 +6,5 @@ // LICENSE : MIT

var assert = require("assert");
exports.createFreezedFilterRuleContext = function (args) {
return Object.freeze(new FilterRuleContext(args));
};
/**

@@ -8,0 +11,0 @@ * Rule context object is passed to each rule as `context`

@@ -46,2 +46,3 @@ import { BaseRuleContext } from "./BaseRuleContext";

}
export declare const createFreezedRuleContext: (args: RuleContextArgs) => Readonly<RuleContext>;
export default class RuleContext implements BaseRuleContext {

@@ -48,0 +49,0 @@ private _ruleId;

@@ -11,2 +11,5 @@ // LICENSE : MIT

var ruleFixer = new rule_fixer_1.default();
exports.createFreezedRuleContext = function (args) {
return Object.freeze(new RuleContext(args));
};
var RuleContext = /** @class */ (function () {

@@ -13,0 +16,0 @@ function RuleContext(args) {

25

lib/kernel/src/core/source-location.d.ts
import SourceCode from "./source-code";
import RuleError, { RuleErrorPadding } from "./rule-error";
import { TxtNode } from "@textlint/ast-node-types";
import { ReportArgs } from "../task/textlint-core-task";
import { TextlintFixCommand } from "@textlint/kernel";
/**
* @typedef {Object} ReportMessage
* @property {string} ruleId
* @property {TxtNode} node
* @property {number} severity
* @property {RuleError} ruleError error is a RuleError instance or any data
*/
export interface ReportMessage {

@@ -21,11 +13,5 @@ ruleId: string;

private source;
/**
*
* @param {SourceCode} source
*/
constructor(source: SourceCode);
/**
* adjust node's location with error's padding location.
* @param {ReportMessage} reportArgs
* @returns {{line: number, column: number, fix?: FixCommand}}
*/

@@ -44,13 +30,4 @@ adjust(reportArgs: ReportArgs): {

* if `fix.isAbsolute` is not absolute position, adjust the position from the `node`.
* @param {TxtNode} node
* @param {RuleError} ruleErrorObject
* @returns {FixCommand|Object}
* @private
*/
_adjustFix(node: TxtNode, ruleErrorObject: RuleError): {} | {
fix: {
range: number[];
text: string;
};
};
private _adjustFix(node, ruleErrorObject);
}

@@ -8,6 +8,2 @@ // LICENSE : MIT

var SourceLocation = /** @class */ (function () {
/**
*
* @param {SourceCode} source
*/
function SourceLocation(source) {

@@ -18,4 +14,2 @@ this.source = source;

* adjust node's location with error's padding location.
* @param {ReportMessage} reportArgs
* @returns {{line: number, column: number, fix?: FixCommand}}
*/

@@ -123,6 +117,2 @@ SourceLocation.prototype.adjust = function (reportArgs) {

* if `fix.isAbsolute` is not absolute position, adjust the position from the `node`.
* @param {TxtNode} node
* @param {RuleError} ruleErrorObject
* @returns {FixCommand|Object}
* @private
*/

@@ -129,0 +119,0 @@ SourceLocation.prototype._adjustFix = function (node, ruleErrorObject) {

import SourceCode from "../core/source-code";
import { TextlintFixResult, TextlintKernelConstructorOptions, TextlintKernelFilterRule, TextlintPluginProcessor, TextlintKernelRule } from "../textlint-kernel-interface";
import { TextlintFixResult, TextlintKernelConstructorOptions, TextlintPluginProcessor } from "../textlint-kernel-interface";
import MessageProcessManager from "../messages/MessageProcessManager";
import { TextlintFilterRuleDescriptors, TextlintRuleDescriptors } from "../descriptor";
export interface FixerProcessorProcessArgs {
config: TextlintKernelConstructorOptions;
configBaseDir?: string;
rules?: TextlintKernelRule[];
filterRules?: TextlintKernelFilterRule[];
ruleDescriptors: TextlintRuleDescriptors;
filterRules: TextlintFilterRuleDescriptors;
sourceCode: SourceCode;

@@ -28,3 +29,3 @@ }

*/
process({config, configBaseDir, rules, filterRules, sourceCode}: FixerProcessorProcessArgs): Promise<TextlintFixResult>;
process({config, configBaseDir, ruleDescriptors, filterRules, sourceCode}: FixerProcessorProcessArgs): Promise<TextlintFixResult>;
}

@@ -10,3 +10,2 @@ // LICENSE : MIT

var task_runner_1 = require("../task/task-runner");
var rule_creator_helper_1 = require("../core/rule-creator-helper");
var FixerProcessor = /** @class */ (function () {

@@ -32,5 +31,5 @@ /**

var _this = this;
var config = _a.config, configBaseDir = _a.configBaseDir, _b = _a.rules, rules = _b === void 0 ? [] : _b, _c = _a.filterRules, filterRules = _c === void 0 ? [] : _c, sourceCode = _a.sourceCode;
assert(config && Array.isArray(rules) && Array.isArray(filterRules) && sourceCode);
var _d = this.processor.processor(sourceCode.ext), preProcess = _d.preProcess, postProcess = _d.postProcess;
var config = _a.config, configBaseDir = _a.configBaseDir, ruleDescriptors = _a.ruleDescriptors, filterRules = _a.filterRules, sourceCode = _a.sourceCode;
assert(sourceCode);
var _b = this.processor.processor(sourceCode.ext), preProcess = _b.preProcess, postProcess = _b.postProcess;
// messages

@@ -47,7 +46,3 @@ var resultFilePath = sourceCode.filePath;

var originalMessages = [];
var fixerProcessList = rules
.filter(function (rule) {
return rule_creator_helper_1.hasFixer(rule.rule);
})
.map(function (fixerRule) {
var fixerProcessList = ruleDescriptors.fixableDescriptors.map(function (ruleDescriptor) {
return function (sourceText) {

@@ -64,4 +59,4 @@ // create new SourceCode object

config: config,
fixerRule: fixerRule,
filterRules: filterRules,
fixableRuleDescriptor: ruleDescriptor,
filterRuleDescriptors: filterRules,
sourceCode: newSourceCode,

@@ -68,0 +63,0 @@ configBaseDir: configBaseDir

@@ -7,5 +7,5 @@ import { TxtNode } from "@textlint/ast-node-types";

*/
export declare class IntermediateFixCommand {
export interface IntermediateFixCommand {
text: string;
range: [number, number];
range: number[];
isAbsolute: boolean;

@@ -12,0 +12,0 @@ }

@@ -5,12 +5,2 @@ "use strict";

/**
* Fix Command object has `range` and `text`.
* `IntermediateFixCommand` has also `isAbsolute` flag value.
*/
var IntermediateFixCommand = /** @class */ (function () {
function IntermediateFixCommand() {
}
return IntermediateFixCommand;
}());
exports.IntermediateFixCommand = IntermediateFixCommand;
/**
* Creates a fix command that inserts text at the specified index in the source text.

@@ -17,0 +7,0 @@ * @param {number} index The 0-based index at which to insert the new text.

export { TextlintKernel } from "./textlint-kernel";
export { TextlintResult, TextlintFixResult, TextlintFixCommand, TextlintMessage, TextlintKernelRule, TextlintKernelFilterRule, TextlintKernelPlugin, TextlintRuleCreator, TextlintRuleOptions, TextlintFilterRuleCreator, TextlintFilterRuleOptions, TextlintPluginCreator, TextlintPluginOptions, TextlintPluginProcessor, TextlintPluginProcessorConstructor } from "./textlint-kernel-interface";
export * from "./descriptor/index";
export { TextlintResult, TextlintFixResult, TextlintFixCommand, TextlintMessage, TextlintKernelRule, TextlintKernelFilterRule, TextlintKernelPlugin, TextlintRuleReporter, TextlintRuleModule, TextlintRuleOptions, TextlintFilterRuleReporter, TextlintFilterRuleOptions, TextlintPluginCreator, TextlintPluginOptions, TextlintPluginProcessor, TextlintPluginProcessorConstructor } from "./textlint-kernel-interface";
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });

@@ -6,7 +9,7 @@ // Kernel

exports.TextlintKernel = textlint_kernel_1.TextlintKernel;
// Kernel Descriptor
__export(require("./descriptor/index"));
// Types
var textlint_kernel_interface_1 = require("./textlint-kernel-interface");
exports.TextlintFixCommand = textlint_kernel_interface_1.TextlintFixCommand;
exports.TextlintMessage = textlint_kernel_interface_1.TextlintMessage;
exports.TextlintPluginProcessor = textlint_kernel_interface_1.TextlintPluginProcessor;
//# sourceMappingURL=index.js.map

@@ -1,9 +0,10 @@

import { TextlintKernelConstructorOptions, TextlintKernelFilterRule, TextlintPluginProcessor, TextlintKernelRule } from "../textlint-kernel-interface";
import { TextlintKernelConstructorOptions, TextlintPluginProcessor, TextlintResult } from "../textlint-kernel-interface";
import MessageProcessManager from "../messages/MessageProcessManager";
import SourceCode from "../core/source-code";
import { TextlintFilterRuleDescriptors, TextlintRuleDescriptors } from "../descriptor";
export interface LinterProcessorArgs {
config: TextlintKernelConstructorOptions;
configBaseDir?: string;
rules?: TextlintKernelRule[];
filterRules?: TextlintKernelFilterRule[];
ruleDescriptors: TextlintRuleDescriptors;
filterRuleDescriptors: TextlintFilterRuleDescriptors;
sourceCode: SourceCode;

@@ -21,13 +22,4 @@ }

* Run linter process
* @param {Config} config
* @param {string} [configBaseDir
* @param {TextlintKernelRule[]} [rules]
* @param {TextlintKernelFilterRule[]} [filterRules]
* @param {SourceCode} sourceCode
* @returns {Promise.<TextlintResult>}
*/
process({config, configBaseDir, rules, filterRules, sourceCode}: LinterProcessorArgs): Promise<{
messages: any[];
filePath: string;
}>;
process({config, configBaseDir, ruleDescriptors, filterRuleDescriptors, sourceCode}: LinterProcessorArgs): Promise<TextlintResult>;
}

@@ -18,19 +18,12 @@ // LICENSE : MIT

* Run linter process
* @param {Config} config
* @param {string} [configBaseDir
* @param {TextlintKernelRule[]} [rules]
* @param {TextlintKernelFilterRule[]} [filterRules]
* @param {SourceCode} sourceCode
* @returns {Promise.<TextlintResult>}
*/
LinterProcessor.prototype.process = function (_a) {
var _this = this;
var config = _a.config, configBaseDir = _a.configBaseDir, _b = _a.rules, rules = _b === void 0 ? [] : _b, _c = _a.filterRules, filterRules = _c === void 0 ? [] : _c, sourceCode = _a.sourceCode;
assert(config && Array.isArray(rules) && Array.isArray(filterRules) && sourceCode);
var _d = this.processor.processor(sourceCode.ext), preProcess = _d.preProcess, postProcess = _d.postProcess;
var config = _a.config, configBaseDir = _a.configBaseDir, ruleDescriptors = _a.ruleDescriptors, filterRuleDescriptors = _a.filterRuleDescriptors, sourceCode = _a.sourceCode;
var _b = this.processor.processor(sourceCode.ext), preProcess = _b.preProcess, postProcess = _b.postProcess;
assert(typeof preProcess === "function" && typeof postProcess === "function", "processor should implement {preProcess, postProcess}");
var task = new linter_task_1.default({
config: config,
rules: rules,
filterRules: filterRules,
ruleDescriptors: ruleDescriptors,
filterRuleDescriptors: filterRuleDescriptors,
sourceCode: sourceCode,

@@ -37,0 +30,0 @@ configBaseDir: configBaseDir

import CoreTask from "./textlint-core-task";
import { TextlintKernelConstructorOptions, TextlintKernelFilterRule, TextlintKernelRule } from "../textlint-kernel-interface";
import { TextlintKernelConstructorOptions } from "../textlint-kernel-interface";
import SourceCode from "../core/source-code";
import { TextlintFilterRuleDescriptors, TextlintFixableRuleDescriptor } from "../descriptor";
export interface TextLintCoreTaskArgs {
config: TextlintKernelConstructorOptions;
fixerRule: TextlintKernelRule;
filterRules: TextlintKernelFilterRule[];
fixableRuleDescriptor: TextlintFixableRuleDescriptor;
filterRuleDescriptors: TextlintFilterRuleDescriptors;
sourceCode: SourceCode;

@@ -13,16 +14,9 @@ configBaseDir?: string;

config: TextlintKernelConstructorOptions;
fixerRule: TextlintKernelRule;
filterRules: TextlintKernelFilterRule[];
fixableRuleDescriptor: TextlintFixableRuleDescriptor;
filterRuleDescriptors: TextlintFilterRuleDescriptors;
sourceCode: SourceCode;
configBaseDir?: string;
/**
* @param {Config} config
* @param {string} [configBaseDir]
* @param {TextlintKernelRule} fixerRule rules has fixer
* @param {TextlintKernelFilterRule[]} filterRules filter rules and config set
* @param {SourceCode} sourceCode
*/
constructor({config, configBaseDir, fixerRule, filterRules, sourceCode}: TextLintCoreTaskArgs);
constructor({config, configBaseDir, fixableRuleDescriptor, filterRuleDescriptors, sourceCode}: TextLintCoreTaskArgs);
start(): void;
_setupRules(): void;
private _setupRules();
}

@@ -15,3 +15,2 @@ // LICENSE : MIT

var textlint_core_task_1 = require("./textlint-core-task");
var rule_creator_helper_1 = require("../core/rule-creator-helper");
var rule_context_1 = require("../core/rule-context");

@@ -22,16 +21,9 @@ var filter_rule_context_1 = require("../core/filter-rule-context");

__extends(TextLintCoreTask, _super);
/**
* @param {Config} config
* @param {string} [configBaseDir]
* @param {TextlintKernelRule} fixerRule rules has fixer
* @param {TextlintKernelFilterRule[]} filterRules filter rules and config set
* @param {SourceCode} sourceCode
*/
function TextLintCoreTask(_a) {
var config = _a.config, configBaseDir = _a.configBaseDir, fixerRule = _a.fixerRule, filterRules = _a.filterRules, sourceCode = _a.sourceCode;
var config = _a.config, configBaseDir = _a.configBaseDir, fixableRuleDescriptor = _a.fixableRuleDescriptor, filterRuleDescriptors = _a.filterRuleDescriptors, sourceCode = _a.sourceCode;
var _this = _super.call(this) || this;
_this.config = config;
_this.configBaseDir = configBaseDir;
_this.fixerRule = fixerRule;
_this.filterRules = filterRules;
_this.fixableRuleDescriptor = fixableRuleDescriptor;
_this.filterRuleDescriptors = filterRuleDescriptors;
_this.sourceCode = sourceCode;

@@ -51,6 +43,6 @@ _this._setupRules();

// setup "rules" field by using a single fixerRule
debug("fixerRule", this.fixerRule);
var ruleContext = new rule_context_1.default({
ruleId: this.fixerRule.ruleId,
ruleOptions: this.fixerRule.options,
debug("fixerRule", this.fixableRuleDescriptor);
var ruleContext = rule_context_1.createFreezedRuleContext({
ruleId: this.fixableRuleDescriptor.id,
ruleOptions: this.fixableRuleDescriptor.normalizedOptions,
sourceCode: sourceCode,

@@ -60,16 +52,12 @@ report: report,

});
var ruleModule = rule_creator_helper_1.getFixer(this.fixerRule.rule);
this.tryToAddListenRule(ruleModule, ruleContext, this.fixerRule.options);
this.tryToAddListenRule(this.fixableRuleDescriptor.fixer, ruleContext, this.fixableRuleDescriptor.normalizedOptions);
// setup "filters" field
debug("filterRules", this.filterRules);
this.filterRules.forEach(function (_a) {
var ruleId = _a.ruleId, rule = _a.rule, options = _a.options;
var ruleContext = new filter_rule_context_1.default({
ruleId: ruleId,
debug("filterRules", this.filterRuleDescriptors);
this.filterRuleDescriptors.descriptors.forEach(function (filterRuleDescriptor) {
var ruleContext = filter_rule_context_1.createFreezedFilterRuleContext({
ruleId: filterRuleDescriptor.id,
sourceCode: sourceCode,
ignoreReport: ignoreReport
});
// "filters" rule is the same with "rules"
var ruleModule = rule_creator_helper_1.getFilter(rule);
_this.tryToAddListenRule(ruleModule, ruleContext, options);
_this.tryToAddListenRule(filterRuleDescriptor.filter, ruleContext, filterRuleDescriptor.normalizedOptions);
});

@@ -76,0 +64,0 @@ };

import CoreTask from "./textlint-core-task";
import { TextlintKernelConstructorOptions, TextlintKernelFilterRule, TextlintKernelRule } from "../textlint-kernel-interface";
import { TextlintKernelConstructorOptions } from "../textlint-kernel-interface";
import SourceCode from "../core/source-code";
import { TextlintFilterRuleDescriptors, TextlintRuleDescriptors } from "../descriptor";
export interface TextLintCoreTaskArgs {
config: TextlintKernelConstructorOptions;
rules: TextlintKernelRule[];
filterRules: TextlintKernelFilterRule[];
ruleDescriptors: TextlintRuleDescriptors;
filterRuleDescriptors: TextlintFilterRuleDescriptors;
sourceCode: SourceCode;

@@ -13,16 +14,9 @@ configBaseDir?: string;

config: TextlintKernelConstructorOptions;
rules: TextlintKernelRule[];
filterRules: TextlintKernelFilterRule[];
ruleDescriptors: TextlintRuleDescriptors;
filterRuleDescriptors: TextlintFilterRuleDescriptors;
sourceCode: SourceCode;
configBaseDir?: string;
/**
* @param {Config} config
* @param {string} [configBaseDir]
* @param {TextlintKernelRule[]} rules rules and config set
* @param {TextlintKernelFilterRule[]} filterRules rules filter rules and config set
* @param {SourceCode} sourceCode
*/
constructor({config, configBaseDir, rules, filterRules, sourceCode}: TextLintCoreTaskArgs);
constructor({config, configBaseDir, ruleDescriptors, filterRuleDescriptors: filterRuleDescriptors, sourceCode}: TextLintCoreTaskArgs);
start(): void;
_setupRules(): void;
}

@@ -15,3 +15,2 @@ // LICENSE : MIT

var textlint_core_task_1 = require("./textlint-core-task");
var rule_creator_helper_1 = require("../core/rule-creator-helper");
var rule_context_1 = require("../core/rule-context");

@@ -22,16 +21,9 @@ var filter_rule_context_1 = require("../core/filter-rule-context");

__extends(TextLintCoreTask, _super);
/**
* @param {Config} config
* @param {string} [configBaseDir]
* @param {TextlintKernelRule[]} rules rules and config set
* @param {TextlintKernelFilterRule[]} filterRules rules filter rules and config set
* @param {SourceCode} sourceCode
*/
function TextLintCoreTask(_a) {
var config = _a.config, configBaseDir = _a.configBaseDir, rules = _a.rules, filterRules = _a.filterRules, sourceCode = _a.sourceCode;
var config = _a.config, configBaseDir = _a.configBaseDir, ruleDescriptors = _a.ruleDescriptors, filterRuleDescriptors = _a.filterRuleDescriptors, sourceCode = _a.sourceCode;
var _this = _super.call(this) || this;
_this.config = config;
_this.configBaseDir = configBaseDir;
_this.rules = rules;
_this.filterRules = filterRules;
_this.ruleDescriptors = ruleDescriptors;
_this.filterRuleDescriptors = filterRuleDescriptors;
_this.sourceCode = sourceCode;

@@ -53,8 +45,8 @@ _this._setupRules();

// see https://github.com/textlint/textlint/issues/219
debug("rules", this.rules);
this.rules.forEach(function (_a) {
var ruleId = _a.ruleId, rule = _a.rule, options = _a.options;
var ruleContext = new rule_context_1.default({
ruleId: ruleId,
ruleOptions: options,
debug("rules", this.ruleDescriptors);
this.ruleDescriptors.lintableDescriptors.forEach(function (ruleDescriptor) {
var ruleOptions = ruleDescriptor.normalizedOptions;
var ruleContext = rule_context_1.createFreezedRuleContext({
ruleId: ruleDescriptor.id,
ruleOptions: ruleOptions,
sourceCode: sourceCode,

@@ -64,11 +56,9 @@ report: report,

});
var ruleCreator = rule_creator_helper_1.getLinter(rule);
_this.tryToAddListenRule(ruleCreator, ruleContext, options);
_this.tryToAddListenRule(ruleDescriptor.linter, ruleContext, ruleOptions);
});
// setup "filters" field
debug("filterRules", this.filterRules);
this.filterRules.forEach(function (_a) {
var ruleId = _a.ruleId, rule = _a.rule, options = _a.options;
var ruleContext = new filter_rule_context_1.default({
ruleId: ruleId,
debug("filterRules", this.filterRuleDescriptors);
this.filterRuleDescriptors.descriptors.forEach(function (filterDescriptor) {
var ruleContext = filter_rule_context_1.createFreezedFilterRuleContext({
ruleId: filterDescriptor.id,
sourceCode: sourceCode,

@@ -78,5 +68,3 @@ ignoreReport: ignoreReport,

});
// "filters" rule is the same with "rules"
var ruleModule = rule_creator_helper_1.getFilter(rule);
_this.tryToAddListenRule(ruleModule, ruleContext, options);
_this.tryToAddListenRule(filterDescriptor.filter, ruleContext, filterDescriptor.normalizedOptions);
});

@@ -83,0 +71,0 @@ };

@@ -7,3 +7,3 @@ /// <reference types="node" />

import { TxtNode } from "@textlint/ast-node-types";
import { RuleCreatorReporter, TextlintFilterRuleCreator, TextlintFilterRuleOptions, TextlintFixCommand, TextlintRuleOptions } from "../textlint-kernel-interface";
import { TextlintRuleReporter, TextlintFilterRuleReporter, TextlintFilterRuleOptions, TextlintFixCommand, TextlintRuleOptions } from "../textlint-kernel-interface";
import { default as RuleContext, RuleReportedObject } from "../core/rule-context";

@@ -81,3 +81,3 @@ import FilterRuleContext from "../core/filter-rule-context";

*/
tryToGetRuleObject(ruleCreator: RuleCreatorReporter, ruleContext: RuleContext, ruleOptions?: TextlintRuleOptions): {
tryToGetRuleObject(ruleCreator: TextlintRuleReporter, ruleContext: Readonly<RuleContext>, ruleOptions?: TextlintRuleOptions): {
[x: string]: ((node: TxtNode) => void | Promise<any>) | undefined;

@@ -88,3 +88,3 @@ };

*/
tryToGetFilterRuleObject(ruleCreator: TextlintFilterRuleCreator, ruleContext: FilterRuleContext, ruleOptions?: TextlintFilterRuleOptions): {
tryToGetFilterRuleObject(ruleCreator: TextlintFilterRuleReporter, ruleContext: Readonly<FilterRuleContext>, ruleOptions?: TextlintFilterRuleOptions): {
[x: string]: ((node: TxtNode) => void | Promise<any>) | undefined;

@@ -95,7 +95,7 @@ };

* @param {Function} ruleCreator
* @param {RuleContext|FilterRuleContext} ruleContext
* @param {Readonly<RuleContext>|Readonly<FilterRuleContext>} ruleContext
* @param {Object|boolean|undefined} ruleOptions
* @returns {Object}
*/
tryToAddListenRule(ruleCreator: RuleCreatorReporter | TextlintFilterRuleCreator, ruleContext: RuleContext | FilterRuleContext, ruleOptions?: TextlintRuleOptions | TextlintFilterRuleOptions): void;
tryToAddListenRule(ruleCreator: TextlintRuleReporter | TextlintFilterRuleReporter, ruleContext: Readonly<RuleContext> | Readonly<FilterRuleContext>, ruleOptions?: TextlintRuleOptions | TextlintFilterRuleOptions): void;
}

@@ -174,3 +174,3 @@ // LICENSE : MIT

* @param {Function} ruleCreator
* @param {RuleContext|FilterRuleContext} ruleContext
* @param {Readonly<RuleContext>|Readonly<FilterRuleContext>} ruleContext
* @param {Object|boolean|undefined} ruleOptions

@@ -177,0 +177,0 @@ * @returns {Object}

@@ -8,14 +8,17 @@ import { TxtNode, TxtNodeType } from "@textlint/ast-node-types";

*/
export declare type RuleCreatorReporter = (context: RuleContext, options?: TextlintRuleOptions) => {
export declare type TextlintRuleReporter = (context: Readonly<RuleContext>, options?: TextlintRuleOptions) => {
[P in TxtNodeType]?: (node: TxtNode) => void | Promise<any>;
};
export declare type TextlintFixableRuleModule = {
linter: TextlintRuleReporter;
fixer: TextlintRuleReporter;
};
/**
* module.export = reporter | { linter, fixer }
*/
export declare type TextlintRuleModule = TextlintRuleReporter | TextlintFixableRuleModule;
/**
* Filter rule reporter function
*/
export declare type TextlintRuleFixableCreator = {
linter: RuleCreatorReporter;
fixer: RuleCreatorReporter;
};
export declare type TextlintRuleCreator = RuleCreatorReporter | TextlintRuleFixableCreator;
export declare type TextlintFilterRuleCreator = (context: FilterRuleContext, options?: TextlintFilterRuleOptions) => {
export declare type TextlintFilterRuleReporter = (context: Readonly<FilterRuleContext>, options?: TextlintFilterRuleOptions) => {
[P in TxtNodeType]?: (node: TxtNode) => void | Promise<any>;

@@ -30,3 +33,3 @@ };

severity?: SeverityLevelTypes;
} | boolean;
};
/**

@@ -38,3 +41,3 @@ * textlint filter rule option values is object or boolean.

[index: string]: any;
} | boolean;
};
/**

@@ -46,3 +49,3 @@ * textlint plugin option values is object or boolean.

[index: string]: any;
} | boolean;
};
export interface TextlintKernelConstructorOptions {

@@ -71,7 +74,17 @@ /**

new (options?: TextlintPluginOptions): TextlintPluginProcessor;
availableExtensions(): Array<string>;
/**
* Should defined `availableExtensions()` as instance method instead of static method.
* @deprecated textlint@11+
* @see https://github.com/textlint/textlint/issues/531
*/
availableExtensions?(): Array<string>;
}
export declare class TextlintPluginProcessor {
constructor(options?: TextlintPluginOptions);
static availableExtensions(): Array<string>;
/**
* Return available extensions for this plugin.
* This extension should start with `.`(dot).
* Example is [".md", ".mkd"]
*/
availableExtensions(): Array<string>;
processor(extension: string): {

@@ -91,13 +104,13 @@ preProcess(text: string, filePath?: string): TxtNode;

plugin: TextlintPluginCreator;
options?: TextlintPluginOptions;
options?: TextlintPluginOptions | boolean;
}
export interface TextlintKernelRule {
ruleId: string;
rule: TextlintRuleCreator;
options?: TextlintRuleOptions;
rule: TextlintRuleModule;
options?: TextlintRuleOptions | boolean;
}
export interface TextlintKernelFilterRule {
ruleId: string;
rule: TextlintFilterRuleCreator;
options?: TextlintRuleOptions;
rule: TextlintFilterRuleReporter;
options?: TextlintFilterRuleOptions | boolean;
}

@@ -112,7 +125,7 @@ export interface TextlintKernelOptions {

}
export declare class TextlintFixCommand {
export interface TextlintFixCommand {
text: string;
range: [number, number];
}
export declare class TextlintMessage {
export interface TextlintMessage {
type: string;

@@ -119,0 +132,0 @@ ruleId: string;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// "range" will be replaced by "text"
var TextlintFixCommand = /** @class */ (function () {
function TextlintFixCommand() {
}
return TextlintFixCommand;
}());
exports.TextlintFixCommand = TextlintFixCommand;
var TextlintMessage = /** @class */ (function () {
function TextlintMessage() {
}
return TextlintMessage;
}());
exports.TextlintMessage = TextlintMessage;
//# sourceMappingURL=textlint-kernel-interface.js.map

@@ -1,2 +0,3 @@

import { TextlintFixResult, TextlintKernelConstructorOptions, TextlintKernelOptions, TextlintPluginProcessor, TextlintResult } from "./textlint-kernel-interface";
import { TextlintFixResult, TextlintKernelConstructorOptions, TextlintKernelOptions, TextlintResult } from "./textlint-kernel-interface";
import { TextlintKernelDescriptor } from "./descriptor";
/**

@@ -45,10 +46,7 @@ * TextlintKernel is core logic written by pure JavaScript.

*/
_parallelProcess({processor, text, options}: {
processor: TextlintPluginProcessor;
_parallelProcess({descriptor, text, options}: {
descriptor: TextlintKernelDescriptor;
text: string;
options: TextlintKernelOptions;
}): Promise<{
messages: any[];
filePath: string;
}>;
}): Promise<TextlintResult>;
/**

@@ -63,4 +61,4 @@ * process text in series for Rules and return {Promise.<TextlintFixResult>}

*/
_sequenceProcess({processor, text, options}: {
processor: TextlintPluginProcessor;
_sequenceProcess({descriptor, text, options}: {
descriptor: TextlintKernelDescriptor;
text: string;

@@ -67,0 +65,0 @@ options: TextlintKernelOptions;

@@ -16,29 +16,4 @@ // MIT © 2017 azu

var sort_messages_process_1 = require("./messages/sort-messages-process");
var descriptor_1 = require("./descriptor");
/**
* @param {TextlintKernelPlugin[]} plugins
* @param {string} ext
* @returns {TextlintKernelPlugin|undefined} PluginConstructor
*/
function findPluginWithExt(plugins, ext) {
if (plugins === void 0) { plugins = []; }
var availablePlugins = plugins.filter(function (kernelPlugin) {
var plugin = kernelPlugin.plugin;
assert.ok(plugin !== undefined, "Processor(" + kernelPlugin.pluginId + " should have { \"pluginId\": string, \"plugin\": plugin }.");
var options = kernelPlugin.options;
return options !== false;
});
var matchPlugins = availablePlugins.filter(function (kernelPlugin) {
var plugin = kernelPlugin.plugin;
// static availableExtensions() method
var textlintKernelProcessor = plugin.Processor;
assert.ok(typeof textlintKernelProcessor.availableExtensions === "function", "Processor(" + textlintKernelProcessor.name + " should have availableExtensions()");
var extList = textlintKernelProcessor.availableExtensions();
return extList.some(function (targetExt) { return targetExt === ext || "." + targetExt === ext; });
});
if (matchPlugins.length === 0) {
return;
}
return matchPlugins[0];
}
/**
* add fileName to trailing of error message

@@ -95,13 +70,9 @@ * @param {string|undefined} fileName

return Promise.resolve().then(function () {
var ext = options.ext;
var plugin = findPluginWithExt(options.plugins, ext);
if (plugin === undefined) {
throw new Error("Not found available plugin for " + ext);
}
var Processor = plugin.plugin.Processor;
var pluginOptions = plugin.options;
assert(Processor !== undefined, "This plugin has not Processor: " + plugin);
var processor = new Processor(pluginOptions);
var descriptor = new descriptor_1.TextlintKernelDescriptor({
rules: options.rules || [],
filterRules: options.filterRules || [],
plugins: options.plugins || []
});
return _this._parallelProcess({
processor: processor,
descriptor: descriptor,
text: text,

@@ -121,15 +92,11 @@ options: options

return Promise.resolve().then(function () {
var ext = options.ext;
var plugin = findPluginWithExt(options.plugins, ext);
if (plugin === undefined) {
throw new Error("Not found available plugin for " + ext);
}
var Processor = plugin.plugin.Processor;
var pluginOptions = plugin.options;
assert(Processor !== undefined, "This plugin has not Processor: " + plugin);
var processor = new Processor(pluginOptions);
var descriptor = new descriptor_1.TextlintKernelDescriptor({
rules: options.rules || [],
filterRules: options.filterRules || [],
plugins: options.plugins || []
});
return _this._sequenceProcess({
processor: processor,
text: text,
options: options
descriptor: descriptor,
options: options,
text: text
});

@@ -148,6 +115,11 @@ });

TextlintKernel.prototype._parallelProcess = function (_a) {
var processor = _a.processor, text = _a.text, options = _a.options;
var ext = options.ext, filePath = options.filePath, rules = options.rules, filterRules = options.filterRules, configBaseDir = options.configBaseDir;
var descriptor = _a.descriptor, text = _a.text, options = _a.options;
var ext = options.ext, filePath = options.filePath, configBaseDir = options.configBaseDir;
var plugin = descriptor.findPluginDescriptorWithExt(ext);
if (plugin === undefined) {
throw new Error("Not found available plugin for " + ext);
}
var processor = plugin.processor;
var _b = processor.processor(ext), preProcess = _b.preProcess, postProcess = _b.postProcess;
assert(typeof preProcess === "function" && typeof postProcess === "function", "processor should implement {preProcess, postProcess}");
assert(typeof preProcess === "function" && typeof postProcess === "function", "processor should implements {preProcess, postProcess}");
var ast = preProcess(text, filePath);

@@ -164,4 +136,4 @@ var sourceCode = new source_code_1.default({

config: this.config,
rules: rules,
filterRules: filterRules,
ruleDescriptors: descriptor.rule,
filterRuleDescriptors: descriptor.filterRule,
sourceCode: sourceCode,

@@ -185,7 +157,11 @@ configBaseDir: configBaseDir

TextlintKernel.prototype._sequenceProcess = function (_a) {
var processor = _a.processor, text = _a.text, options = _a.options;
var ext = options.ext, filePath = options.filePath, rules = options.rules, filterRules = options.filterRules, configBaseDir = options.configBaseDir;
assert(processor, "processor is not found for " + ext);
var descriptor = _a.descriptor, text = _a.text, options = _a.options;
var ext = options.ext, filePath = options.filePath, configBaseDir = options.configBaseDir;
var plugin = descriptor.findPluginDescriptorWithExt(ext);
if (plugin === undefined) {
throw new Error("Not found available plugin for " + ext);
}
var processor = plugin.processor;
var _b = processor.processor(ext), preProcess = _b.preProcess, postProcess = _b.postProcess;
assert(typeof preProcess === "function" && typeof postProcess === "function", "processor should implement {preProcess, postProcess}");
assert(typeof preProcess === "function" && typeof postProcess === "function", "processor should implements {preProcess, postProcess}");
var ast = preProcess(text, filePath);

@@ -202,4 +178,4 @@ var sourceCode = new source_code_1.default({

config: this.config,
rules: rules,
filterRules: filterRules,
ruleDescriptors: descriptor.rule,
filterRules: descriptor.filterRule,
sourceCode: sourceCode,

@@ -206,0 +182,0 @@ configBaseDir: configBaseDir

{
"name": "@textlint/kernel",
"version": "2.0.9",
"version": "2.1.0-alpha.0f2fd6f9",
"description": "textlint kernel is core logic by pure JavaScript.",

@@ -36,5 +36,5 @@ "keywords": [

"dependencies": {
"@textlint/ast-node-types": "^4.0.2",
"@textlint/ast-traverse": "^2.0.8",
"@textlint/feature-flag": "^3.0.4",
"@textlint/ast-node-types": "^4.1.0-alpha.0f2fd6f9",
"@textlint/ast-traverse": "^2.1.0-alpha.0f2fd6f9",
"@textlint/feature-flag": "^3.1.0-alpha.0f2fd6f9",
"@types/bluebird": "^3.5.18",

@@ -44,2 +44,3 @@ "bluebird": "^3.5.1",

"deep-equal": "^1.0.1",
"map-like": "^2.0.0",
"object-assign": "^4.1.1",

@@ -49,17 +50,17 @@ "structured-source": "^3.0.2"

"devDependencies": {
"@textlint/markdown-to-ast": "^6.0.8",
"@textlint/textlint-plugin-markdown": "^4.0.10",
"@types/mocha": "^2.2.43",
"@textlint/markdown-to-ast": "^6.1.0-alpha.0f2fd6f9",
"@types/deep-equal": "^1.0.1",
"@types/mocha": "^5.2.0",
"@types/node": "^8.0.28",
"cpx": "^1.5.0",
"cross-env": "^5.0.5",
"mocha": "^4.0.1",
"mocha": "^5.1.1",
"npm-run-all": "^4.1.1",
"rimraf": "^2.6.2",
"shelljs": "^0.7.7",
"ts-node": "^3.3.0",
"ts-node-test-register": "^1.0.1",
"typescript": "~2.6.1",
"shelljs": "^0.8.2",
"ts-node": "^7.0.0",
"ts-node-test-register": "^4.0.0",
"typescript": "~2.8.4",
"unist-util-select": "^1.5.0"
}
}

@@ -32,2 +32,6 @@ // LICENSE : MIT

export const createFreezedFilterRuleContext = (args: FilterRuleContextArgs) => {
return Object.freeze(new FilterRuleContext(args));
};
/**

@@ -34,0 +38,0 @@ * Rule context object is passed to each rule as `context`

@@ -59,2 +59,6 @@ // LICENSE : MIT

export const createFreezedRuleContext = (args: RuleContextArgs) => {
return Object.freeze(new RuleContext(args));
};
export default class RuleContext implements BaseRuleContext {

@@ -61,0 +65,0 @@ private _ruleId: string;

@@ -13,9 +13,2 @@ // LICENSE : MIT

/**
* @typedef {Object} ReportMessage
* @property {string} ruleId
* @property {TxtNode} node
* @property {number} severity
* @property {RuleError} ruleError error is a RuleError instance or any data
*/
export interface ReportMessage {

@@ -31,6 +24,2 @@ ruleId: string;

/**
*
* @param {SourceCode} source
*/
constructor(source: SourceCode) {

@@ -42,4 +31,2 @@ this.source = source;

* adjust node's location with error's padding location.
* @param {ReportMessage} reportArgs
* @returns {{line: number, column: number, fix?: FixCommand}}
*/

@@ -186,8 +173,4 @@ adjust(reportArgs: ReportArgs): { line: number; column: number; fix?: TextlintFixCommand } {

* if `fix.isAbsolute` is not absolute position, adjust the position from the `node`.
* @param {TxtNode} node
* @param {RuleError} ruleErrorObject
* @returns {FixCommand|Object}
* @private
*/
_adjustFix(node: TxtNode, ruleErrorObject: RuleError) {
private _adjustFix(node: TxtNode, ruleErrorObject: RuleError) {
const nodeRange = node.range;

@@ -194,0 +177,0 @@ // if not found `fix`, return empty object

// LICENSE : MIT
"use strict";
const debug = require("debug")("textlint:fixer-processor");

@@ -9,12 +10,10 @@ import * as assert from "assert";

import TaskRunner from "../task/task-runner";
import { hasFixer } from "../core/rule-creator-helper";
import {
TextlintFixResult,
TextlintKernelConstructorOptions,
TextlintKernelFilterRule,
TextlintPluginProcessor,
TextlintKernelRule,
TextlintMessage
TextlintMessage,
TextlintPluginProcessor
} from "../textlint-kernel-interface";
import MessageProcessManager from "../messages/MessageProcessManager";
import { TextlintFilterRuleDescriptors, TextlintRuleDescriptors } from "../descriptor";

@@ -24,4 +23,4 @@ export interface FixerProcessorProcessArgs {

configBaseDir?: string;
rules?: TextlintKernelRule[];
filterRules?: TextlintKernelFilterRule[];
ruleDescriptors: TextlintRuleDescriptors;
filterRules: TextlintFilterRuleDescriptors;
sourceCode: SourceCode;

@@ -55,7 +54,7 @@ }

configBaseDir,
rules = [],
filterRules = [],
ruleDescriptors,
filterRules,
sourceCode
}: FixerProcessorProcessArgs): Promise<TextlintFixResult> {
assert(config && Array.isArray(rules) && Array.isArray(filterRules) && sourceCode);
assert(sourceCode);
const { preProcess, postProcess } = this.processor.processor(sourceCode.ext);

@@ -73,46 +72,42 @@ // messages

const originalMessages: TextlintMessage[] = [];
const fixerProcessList = rules
.filter(rule => {
return hasFixer(rule.rule);
})
.map(fixerRule => {
return (sourceText: string): Promise<string> => {
// create new SourceCode object
const newSourceCode = new SourceCode({
text: sourceText,
ast: preProcess(sourceText, sourceCode.filePath),
filePath: resultFilePath,
ext: sourceCode.ext
});
// create new Task
const task = new FixerTask({
config,
fixerRule,
filterRules,
sourceCode: newSourceCode,
configBaseDir
});
const fixerProcessList = ruleDescriptors.fixableDescriptors.map(ruleDescriptor => {
return (sourceText: string): Promise<string> => {
// create new SourceCode object
const newSourceCode = new SourceCode({
text: sourceText,
ast: preProcess(sourceText, sourceCode.filePath),
filePath: resultFilePath,
ext: sourceCode.ext
});
// create new Task
const task = new FixerTask({
config,
fixableRuleDescriptor: ruleDescriptor,
filterRuleDescriptors: filterRules,
sourceCode: newSourceCode,
configBaseDir
});
return TaskRunner.process(task).then(messages => {
const result = postProcess(messages, sourceCode.filePath);
const filteredResult = {
messages: this.messageProcessManager.process(result.messages),
filePath: result.filePath ? result.filePath : `<Unkown${sourceCode.ext}>`
};
// TODO: should be removed resultFilePath
resultFilePath = filteredResult.filePath;
const applied = SourceCodeFixer.applyFixes(newSourceCode, filteredResult.messages);
// add messages
Array.prototype.push.apply(applyingMessages, applied.applyingMessages);
Array.prototype.push.apply(remainingMessages, applied.remainingMessages);
Array.prototype.push.apply(originalMessages, applied.messages);
// if not fixed, still use current sourceText
if (!applied.fixed) {
return sourceText;
}
// if fixed, use fixed text at next
return applied.output;
});
};
});
return TaskRunner.process(task).then(messages => {
const result = postProcess(messages, sourceCode.filePath);
const filteredResult = {
messages: this.messageProcessManager.process(result.messages),
filePath: result.filePath ? result.filePath : `<Unkown${sourceCode.ext}>`
};
// TODO: should be removed resultFilePath
resultFilePath = filteredResult.filePath;
const applied = SourceCodeFixer.applyFixes(newSourceCode, filteredResult.messages);
// add messages
Array.prototype.push.apply(applyingMessages, applied.applyingMessages);
Array.prototype.push.apply(remainingMessages, applied.remainingMessages);
Array.prototype.push.apply(originalMessages, applied.messages);
// if not fixed, still use current sourceText
if (!applied.fixed) {
return sourceText;
}
// if fixed, use fixed text at next
return applied.output;
});
};
});

@@ -119,0 +114,0 @@ const promiseTask = fixerProcessList.reduce((promise, fixerProcess) => {

@@ -9,5 +9,5 @@ import * as assert from "assert";

*/
export class IntermediateFixCommand {
export interface IntermediateFixCommand {
text: string;
range: [number, number];
range: number[];
isAbsolute: boolean;

@@ -14,0 +14,0 @@ }

// Kernel
export { TextlintKernel } from "./textlint-kernel";
// Kernel Descriptor
export * from "./descriptor/index";
// Types

@@ -15,6 +17,7 @@ export {

// textlint rule interface
TextlintRuleCreator,
TextlintRuleReporter,
TextlintRuleModule,
TextlintRuleOptions,
// textlint filter rule interface
TextlintFilterRuleCreator,
TextlintFilterRuleReporter,
TextlintFilterRuleOptions,

@@ -21,0 +24,0 @@ // textlint plugin interface

@@ -8,8 +8,8 @@ // LICENSE : MIT

TextlintKernelConstructorOptions,
TextlintKernelFilterRule,
TextlintPluginProcessor,
TextlintKernelRule
TextlintResult
} from "../textlint-kernel-interface";
import MessageProcessManager from "../messages/MessageProcessManager";
import SourceCode from "../core/source-code";
import { TextlintFilterRuleDescriptors, TextlintRuleDescriptors } from "../descriptor";

@@ -19,4 +19,4 @@ export interface LinterProcessorArgs {

configBaseDir?: string;
rules?: TextlintKernelRule[];
filterRules?: TextlintKernelFilterRule[];
ruleDescriptors: TextlintRuleDescriptors;
filterRuleDescriptors: TextlintFilterRuleDescriptors;
sourceCode: SourceCode;

@@ -40,11 +40,10 @@ }

* Run linter process
* @param {Config} config
* @param {string} [configBaseDir
* @param {TextlintKernelRule[]} [rules]
* @param {TextlintKernelFilterRule[]} [filterRules]
* @param {SourceCode} sourceCode
* @returns {Promise.<TextlintResult>}
*/
process({ config, configBaseDir, rules = [], filterRules = [], sourceCode }: LinterProcessorArgs) {
assert(config && Array.isArray(rules) && Array.isArray(filterRules) && sourceCode);
process({
config,
configBaseDir,
ruleDescriptors,
filterRuleDescriptors,
sourceCode
}: LinterProcessorArgs): Promise<TextlintResult> {
const { preProcess, postProcess } = this.processor.processor(sourceCode.ext);

@@ -57,4 +56,4 @@ assert(

config,
rules,
filterRules,
ruleDescriptors: ruleDescriptors,
filterRuleDescriptors: filterRuleDescriptors,
sourceCode,

@@ -61,0 +60,0 @@ configBaseDir

// LICENSE : MIT
"use strict";
import CoreTask from "./textlint-core-task";
import { getFilter, getFixer } from "../core/rule-creator-helper";
import RuleContext from "../core/rule-context";
import FilterRuleContext from "../core/filter-rule-context";
import {
TextlintKernelConstructorOptions,
TextlintKernelFilterRule,
TextlintKernelRule
} from "../textlint-kernel-interface";
import { createFreezedRuleContext } from "../core/rule-context";
import { createFreezedFilterRuleContext } from "../core/filter-rule-context";
import { TextlintKernelConstructorOptions } from "../textlint-kernel-interface";
import SourceCode from "../core/source-code";
import { TextlintFilterRuleDescriptors, TextlintFixableRuleDescriptor } from "../descriptor";

@@ -18,4 +14,4 @@ const debug = require("debug")("textlint:TextLintCoreTask");

config: TextlintKernelConstructorOptions;
fixerRule: TextlintKernelRule;
filterRules: TextlintKernelFilterRule[];
fixableRuleDescriptor: TextlintFixableRuleDescriptor;
filterRuleDescriptors: TextlintFilterRuleDescriptors;
sourceCode: SourceCode;

@@ -27,20 +23,19 @@ configBaseDir?: string;

config: TextlintKernelConstructorOptions;
fixerRule: TextlintKernelRule;
filterRules: TextlintKernelFilterRule[];
fixableRuleDescriptor: TextlintFixableRuleDescriptor;
filterRuleDescriptors: TextlintFilterRuleDescriptors;
sourceCode: SourceCode;
configBaseDir?: string;
/**
* @param {Config} config
* @param {string} [configBaseDir]
* @param {TextlintKernelRule} fixerRule rules has fixer
* @param {TextlintKernelFilterRule[]} filterRules filter rules and config set
* @param {SourceCode} sourceCode
*/
constructor({ config, configBaseDir, fixerRule, filterRules, sourceCode }: TextLintCoreTaskArgs) {
constructor({
config,
configBaseDir,
fixableRuleDescriptor,
filterRuleDescriptors,
sourceCode
}: TextLintCoreTaskArgs) {
super();
this.config = config;
this.configBaseDir = configBaseDir;
this.fixerRule = fixerRule;
this.filterRules = filterRules;
this.fixableRuleDescriptor = fixableRuleDescriptor;
this.filterRuleDescriptors = filterRuleDescriptors;
this.sourceCode = sourceCode;

@@ -54,3 +49,3 @@ this._setupRules();

_setupRules() {
private _setupRules() {
// rule

@@ -61,6 +56,6 @@ const sourceCode = this.sourceCode;

// setup "rules" field by using a single fixerRule
debug("fixerRule", this.fixerRule);
const ruleContext = new RuleContext({
ruleId: this.fixerRule.ruleId,
ruleOptions: this.fixerRule.options,
debug("fixerRule", this.fixableRuleDescriptor);
const ruleContext = createFreezedRuleContext({
ruleId: this.fixableRuleDescriptor.id,
ruleOptions: this.fixableRuleDescriptor.normalizedOptions,
sourceCode,

@@ -70,17 +65,18 @@ report,

});
const ruleModule = getFixer(this.fixerRule.rule);
this.tryToAddListenRule(ruleModule, ruleContext, this.fixerRule.options);
this.tryToAddListenRule(
this.fixableRuleDescriptor.fixer,
ruleContext,
this.fixableRuleDescriptor.normalizedOptions
);
// setup "filters" field
debug("filterRules", this.filterRules);
this.filterRules.forEach(({ ruleId, rule, options }) => {
const ruleContext = new FilterRuleContext({
ruleId,
debug("filterRules", this.filterRuleDescriptors);
this.filterRuleDescriptors.descriptors.forEach(filterRuleDescriptor => {
const ruleContext = createFreezedFilterRuleContext({
ruleId: filterRuleDescriptor.id,
sourceCode,
ignoreReport
});
// "filters" rule is the same with "rules"
const ruleModule = getFilter(rule);
this.tryToAddListenRule(ruleModule, ruleContext, options);
this.tryToAddListenRule(filterRuleDescriptor.filter, ruleContext, filterRuleDescriptor.normalizedOptions);
});
}
}
// LICENSE : MIT
"use strict";
import CoreTask from "./textlint-core-task";
import { getFilter, getLinter } from "../core/rule-creator-helper";
import RuleContext from "../core/rule-context";
import FilterRuleContext from "../core/filter-rule-context";
import {
TextlintKernelConstructorOptions,
TextlintKernelFilterRule,
TextlintKernelRule
} from "../textlint-kernel-interface";
import { createFreezedRuleContext } from "../core/rule-context";
import { createFreezedFilterRuleContext } from "../core/filter-rule-context";
import { TextlintKernelConstructorOptions } from "../textlint-kernel-interface";
import SourceCode from "../core/source-code";
import { TextlintFilterRuleDescriptors, TextlintRuleDescriptors } from "../descriptor";

@@ -18,4 +14,4 @@ const debug = require("debug")("textlint:TextLintCoreTask");

config: TextlintKernelConstructorOptions;
rules: TextlintKernelRule[];
filterRules: TextlintKernelFilterRule[];
ruleDescriptors: TextlintRuleDescriptors;
filterRuleDescriptors: TextlintFilterRuleDescriptors;
sourceCode: SourceCode;

@@ -27,20 +23,19 @@ configBaseDir?: string;

config: TextlintKernelConstructorOptions;
rules: TextlintKernelRule[];
filterRules: TextlintKernelFilterRule[];
ruleDescriptors: TextlintRuleDescriptors;
filterRuleDescriptors: TextlintFilterRuleDescriptors;
sourceCode: SourceCode;
configBaseDir?: string;
/**
* @param {Config} config
* @param {string} [configBaseDir]
* @param {TextlintKernelRule[]} rules rules and config set
* @param {TextlintKernelFilterRule[]} filterRules rules filter rules and config set
* @param {SourceCode} sourceCode
*/
constructor({ config, configBaseDir, rules, filterRules, sourceCode }: TextLintCoreTaskArgs) {
constructor({
config,
configBaseDir,
ruleDescriptors,
filterRuleDescriptors: filterRuleDescriptors,
sourceCode
}: TextLintCoreTaskArgs) {
super();
this.config = config;
this.configBaseDir = configBaseDir;
this.rules = rules;
this.filterRules = filterRules;
this.ruleDescriptors = ruleDescriptors;
this.filterRuleDescriptors = filterRuleDescriptors;
this.sourceCode = sourceCode;

@@ -62,7 +57,8 @@ this._setupRules();

// see https://github.com/textlint/textlint/issues/219
debug("rules", this.rules);
this.rules.forEach(({ ruleId, rule, options }) => {
const ruleContext = new RuleContext({
ruleId,
ruleOptions: options,
debug("rules", this.ruleDescriptors);
this.ruleDescriptors.lintableDescriptors.forEach(ruleDescriptor => {
const ruleOptions = ruleDescriptor.normalizedOptions;
const ruleContext = createFreezedRuleContext({
ruleId: ruleDescriptor.id,
ruleOptions: ruleOptions,
sourceCode,

@@ -72,10 +68,9 @@ report,

});
const ruleCreator = getLinter(rule);
this.tryToAddListenRule(ruleCreator, ruleContext, options);
this.tryToAddListenRule(ruleDescriptor.linter, ruleContext, ruleOptions);
});
// setup "filters" field
debug("filterRules", this.filterRules);
this.filterRules.forEach(({ ruleId, rule, options }) => {
const ruleContext = new FilterRuleContext({
ruleId,
debug("filterRules", this.filterRuleDescriptors);
this.filterRuleDescriptors.descriptors.forEach(filterDescriptor => {
const ruleContext = createFreezedFilterRuleContext({
ruleId: filterDescriptor.id,
sourceCode,

@@ -85,7 +80,5 @@ ignoreReport,

});
// "filters" rule is the same with "rules"
const ruleModule = getFilter(rule);
this.tryToAddListenRule(ruleModule, ruleContext, options);
this.tryToAddListenRule(filterDescriptor.filter, ruleContext, filterDescriptor.normalizedOptions);
});
}
}

@@ -16,4 +16,4 @@ // LICENSE : MIT

import {
RuleCreatorReporter,
TextlintFilterRuleCreator,
TextlintRuleReporter,
TextlintFilterRuleReporter,
TextlintFilterRuleOptions,

@@ -208,3 +208,7 @@ TextlintFixCommand,

*/
tryToGetRuleObject(ruleCreator: RuleCreatorReporter, ruleContext: RuleContext, ruleOptions?: TextlintRuleOptions) {
tryToGetRuleObject(
ruleCreator: TextlintRuleReporter,
ruleContext: Readonly<RuleContext>,
ruleOptions?: TextlintRuleOptions
) {
try {

@@ -222,4 +226,4 @@ return ruleCreator(ruleContext, ruleOptions);

tryToGetFilterRuleObject(
ruleCreator: TextlintFilterRuleCreator,
ruleContext: FilterRuleContext,
ruleCreator: TextlintFilterRuleReporter,
ruleContext: Readonly<FilterRuleContext>,
ruleOptions?: TextlintFilterRuleOptions

@@ -238,3 +242,3 @@ ) {

* @param {Function} ruleCreator
* @param {RuleContext|FilterRuleContext} ruleContext
* @param {Readonly<RuleContext>|Readonly<FilterRuleContext>} ruleContext
* @param {Object|boolean|undefined} ruleOptions

@@ -244,4 +248,4 @@ * @returns {Object}

tryToAddListenRule(
ruleCreator: RuleCreatorReporter | TextlintFilterRuleCreator,
ruleContext: RuleContext | FilterRuleContext,
ruleCreator: TextlintRuleReporter | TextlintFilterRuleReporter,
ruleContext: Readonly<RuleContext> | Readonly<FilterRuleContext>,
ruleOptions?: TextlintRuleOptions | TextlintFilterRuleOptions

@@ -251,4 +255,12 @@ ): void {

ruleContext instanceof RuleContext
? this.tryToGetRuleObject(ruleCreator as RuleCreatorReporter, ruleContext, ruleOptions)
: this.tryToGetFilterRuleObject(ruleCreator as TextlintFilterRuleCreator, ruleContext, ruleOptions);
? this.tryToGetRuleObject(
ruleCreator as TextlintRuleReporter,
ruleContext as Readonly<RuleContext>,
ruleOptions
)
: this.tryToGetFilterRuleObject(
ruleCreator as TextlintFilterRuleReporter,
ruleContext as Readonly<FilterRuleContext>,
ruleOptions
);
const types = Object.keys(ruleObject) as (keyof typeof ruleObject)[];

@@ -255,0 +267,0 @@ types.forEach((nodeType: keyof typeof ruleObject) => {

@@ -9,13 +9,16 @@ // rule config

*/
export type RuleCreatorReporter = (
context: RuleContext,
export type TextlintRuleReporter = (
context: Readonly<RuleContext>,
options?: TextlintRuleOptions
) => { [P in TxtNodeType]?: (node: TxtNode) => void | Promise<any> };
export type TextlintFixableRuleModule = { linter: TextlintRuleReporter; fixer: TextlintRuleReporter };
/**
* module.export = reporter | { linter, fixer }
*/
export type TextlintRuleModule = TextlintRuleReporter | TextlintFixableRuleModule;
/**
* Filter rule reporter function
*/
export type TextlintRuleFixableCreator = { linter: RuleCreatorReporter; fixer: RuleCreatorReporter };
export type TextlintRuleCreator = RuleCreatorReporter | TextlintRuleFixableCreator;
export type TextlintFilterRuleCreator = (
context: FilterRuleContext,
export type TextlintFilterRuleReporter = (
context: Readonly<FilterRuleContext>,
options?: TextlintFilterRuleOptions

@@ -28,9 +31,7 @@ ) => { [P in TxtNodeType]?: (node: TxtNode) => void | Promise<any> };

*/
export type TextlintRuleOptions =
| {
[index: string]: any;
export type TextlintRuleOptions = {
[index: string]: any;
severity?: SeverityLevelTypes;
}
| boolean;
severity?: SeverityLevelTypes;
};

@@ -41,7 +42,5 @@ /**

*/
export type TextlintFilterRuleOptions =
| {
[index: string]: any;
}
| boolean;
export type TextlintFilterRuleOptions = {
[index: string]: any;
};

@@ -52,7 +51,5 @@ /**

*/
export type TextlintPluginOptions =
| {
[index: string]: any;
}
| boolean;
export type TextlintPluginOptions = {
[index: string]: any;
};

@@ -99,3 +96,8 @@ export interface TextlintKernelConstructorOptions {

availableExtensions(): Array<string>;
/**
* Should defined `availableExtensions()` as instance method instead of static method.
* @deprecated textlint@11+
* @see https://github.com/textlint/textlint/issues/531
*/
availableExtensions?(): Array<string>;
}

@@ -106,3 +108,8 @@

static availableExtensions(): Array<string>;
/**
* Return available extensions for this plugin.
* This extension should start with `.`(dot).
* Example is [".md", ".mkd"]
*/
availableExtensions(): Array<string>;

@@ -129,3 +136,3 @@ processor(

// plugin options
options?: TextlintPluginOptions;
options?: TextlintPluginOptions | boolean;
}

@@ -138,6 +145,6 @@

// For example, `rule: require("textlint-rule-example")`
rule: TextlintRuleCreator;
rule: TextlintRuleModule;
// rule options
// Often rule option is written in .textlintrc
options?: TextlintRuleOptions;
options?: TextlintRuleOptions | boolean;
}

@@ -149,6 +156,6 @@

// filter rule module instance
rule: TextlintFilterRuleCreator;
rule: TextlintFilterRuleReporter;
// filter rule options
// Often rule option is written in .textlintrc
options?: TextlintRuleOptions;
options?: TextlintFilterRuleOptions | boolean;
}

@@ -174,3 +181,3 @@

// "range" will be replaced by "text"
export class TextlintFixCommand {
export interface TextlintFixCommand {
text: string;

@@ -180,3 +187,3 @@ range: [number, number];

export class TextlintMessage {
export interface TextlintMessage {
// See src/shared/type/MessageType.js

@@ -183,0 +190,0 @@ // Message Type

// MIT © 2017 azu
"use strict";
const assert = require("assert");
import * as assert from "assert";
import SourceCode from "./core/source-code";

@@ -19,41 +19,7 @@ // sequence

TextlintKernelOptions,
TextlintKernelPlugin,
TextlintPluginProcessor,
TextlintPluginProcessorConstructor,
TextlintResult
} from "./textlint-kernel-interface";
import { TextlintKernelDescriptor } from "./descriptor";
/**
* @param {TextlintKernelPlugin[]} plugins
* @param {string} ext
* @returns {TextlintKernelPlugin|undefined} PluginConstructor
*/
function findPluginWithExt(plugins: TextlintKernelPlugin[] = [], ext: string) {
const availablePlugins = plugins.filter(kernelPlugin => {
const plugin = kernelPlugin.plugin;
assert.ok(
plugin !== undefined,
`Processor(${kernelPlugin.pluginId} should have { "pluginId": string, "plugin": plugin }.`
);
const options = kernelPlugin.options;
return options !== false;
});
const matchPlugins = availablePlugins.filter(kernelPlugin => {
const plugin = kernelPlugin.plugin;
// static availableExtensions() method
const textlintKernelProcessor: TextlintPluginProcessorConstructor = plugin.Processor;
assert.ok(
typeof textlintKernelProcessor.availableExtensions === "function",
`Processor(${textlintKernelProcessor.name} should have availableExtensions()`
);
const extList = textlintKernelProcessor.availableExtensions();
return extList.some(targetExt => targetExt === ext || "." + targetExt === ext);
});
if (matchPlugins.length === 0) {
return;
}
return matchPlugins[0];
}
/**
* add fileName to trailing of error message

@@ -114,13 +80,9 @@ * @param {string|undefined} fileName

return Promise.resolve().then(() => {
const ext = options.ext;
const plugin = findPluginWithExt(options.plugins, ext);
if (plugin === undefined) {
throw new Error(`Not found available plugin for ${ext}`);
}
const Processor = plugin.plugin.Processor;
const pluginOptions = plugin.options;
assert(Processor !== undefined, `This plugin has not Processor: ${plugin}`);
const processor = new Processor(pluginOptions);
const descriptor = new TextlintKernelDescriptor({
rules: options.rules || [],
filterRules: options.filterRules || [],
plugins: options.plugins || []
});
return this._parallelProcess({
processor,
descriptor,
text,

@@ -140,15 +102,11 @@ options

return Promise.resolve().then(() => {
const ext = options.ext;
const plugin = findPluginWithExt(options.plugins, ext);
if (plugin === undefined) {
throw new Error(`Not found available plugin for ${ext}`);
}
const Processor = plugin.plugin.Processor;
const pluginOptions = plugin.options;
assert(Processor !== undefined, `This plugin has not Processor: ${plugin}`);
const processor = new Processor(pluginOptions);
const descriptor = new TextlintKernelDescriptor({
rules: options.rules || [],
filterRules: options.filterRules || [],
plugins: options.plugins || []
});
return this._sequenceProcess({
processor,
text,
options
descriptor,
options,
text
});

@@ -168,15 +126,20 @@ });

_parallelProcess({
processor,
descriptor,
text,
options
}: {
processor: TextlintPluginProcessor;
descriptor: TextlintKernelDescriptor;
text: string;
options: TextlintKernelOptions;
}) {
const { ext, filePath, rules, filterRules, configBaseDir } = options;
const { ext, filePath, configBaseDir } = options;
const plugin = descriptor.findPluginDescriptorWithExt(ext);
if (plugin === undefined) {
throw new Error(`Not found available plugin for ${ext}`);
}
const processor = plugin.processor;
const { preProcess, postProcess } = processor.processor(ext);
assert(
typeof preProcess === "function" && typeof postProcess === "function",
"processor should implement {preProcess, postProcess}"
"processor should implements {preProcess, postProcess}"
);

@@ -194,4 +157,4 @@ const ast = preProcess(text, filePath);

config: this.config,
rules,
filterRules,
ruleDescriptors: descriptor.rule,
filterRuleDescriptors: descriptor.filterRule,
sourceCode,

@@ -216,16 +179,20 @@ configBaseDir

_sequenceProcess({
processor,
descriptor,
text,
options
}: {
processor: TextlintPluginProcessor;
descriptor: TextlintKernelDescriptor;
text: string;
options: TextlintKernelOptions;
}): Promise<TextlintFixResult> {
const { ext, filePath, rules, filterRules, configBaseDir } = options;
assert(processor, `processor is not found for ${ext}`);
const { ext, filePath, configBaseDir } = options;
const plugin = descriptor.findPluginDescriptorWithExt(ext);
if (plugin === undefined) {
throw new Error(`Not found available plugin for ${ext}`);
}
const processor = plugin.processor;
const { preProcess, postProcess } = processor.processor(ext);
assert(
typeof preProcess === "function" && typeof postProcess === "function",
"processor should implement {preProcess, postProcess}"
"processor should implements {preProcess, postProcess}"
);

@@ -243,4 +210,4 @@ const ast = preProcess(text, filePath);

config: this.config,
rules,
filterRules,
ruleDescriptors: descriptor.rule,
filterRules: descriptor.filterRule,
sourceCode,

@@ -247,0 +214,0 @@ configBaseDir

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc