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

@textlint/kernel

Package Overview
Dependencies
Maintainers
2
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.2 to 2.0.3

44

lib/ast-node-types/src/index.d.ts

@@ -6,24 +6,24 @@ /**

*/
export declare const ASTNodeTypes: {
Document: string;
Paragraph: string;
BlockQuote: string;
ListItem: string;
List: string;
Header: string;
CodeBlock: string;
HtmlBlock: string;
ReferenceDef: string;
HorizontalRule: string;
Comment: string;
Str: string;
Break: string;
Emphasis: string;
Strong: string;
Html: string;
Link: string;
Image: string;
Code: string;
Delete: string;
};
export declare enum ASTNodeTypes {
Document = "Document",
Paragraph = "Paragraph",
BlockQuote = "BlockQuote",
ListItem = "ListItem",
List = "List",
Header = "Header",
CodeBlock = "CodeBlock",
HtmlBlock = "HtmlBlock",
ReferenceDef = "ReferenceDef",
HorizontalRule = "HorizontalRule",
Comment = "Comment",
Str = "Str",
Break = "Break",
Emphasis = "Emphasis",
Strong = "Strong",
Html = "Html",
Link = "Link",
Image = "Image",
Code = "Code",
Delete = "Delete",
}
/**

@@ -30,0 +30,0 @@ * Key of ASTNodeTypes or any string

@@ -9,25 +9,26 @@ // MIT © 2017 azu

*/
exports.ASTNodeTypes = {
Document: "Document",
Paragraph: "Paragraph",
BlockQuote: "BlockQuote",
ListItem: "ListItem",
List: "List",
Header: "Header",
CodeBlock: "CodeBlock",
HtmlBlock: "HtmlBlock",
ReferenceDef: "ReferenceDef",
HorizontalRule: "HorizontalRule",
Comment: "Comment",
var ASTNodeTypes;
(function (ASTNodeTypes) {
ASTNodeTypes["Document"] = "Document";
ASTNodeTypes["Paragraph"] = "Paragraph";
ASTNodeTypes["BlockQuote"] = "BlockQuote";
ASTNodeTypes["ListItem"] = "ListItem";
ASTNodeTypes["List"] = "List";
ASTNodeTypes["Header"] = "Header";
ASTNodeTypes["CodeBlock"] = "CodeBlock";
ASTNodeTypes["HtmlBlock"] = "HtmlBlock";
ASTNodeTypes["ReferenceDef"] = "ReferenceDef";
ASTNodeTypes["HorizontalRule"] = "HorizontalRule";
ASTNodeTypes["Comment"] = "Comment";
// inline
Str: "Str",
Break: "Break",
Emphasis: "Emphasis",
Strong: "Strong",
Html: "Html",
Link: "Link",
Image: "Image",
Code: "Code",
Delete: "Delete"
};
ASTNodeTypes["Str"] = "Str";
ASTNodeTypes["Break"] = "Break";
ASTNodeTypes["Emphasis"] = "Emphasis";
ASTNodeTypes["Strong"] = "Strong";
ASTNodeTypes["Html"] = "Html";
ASTNodeTypes["Link"] = "Link";
ASTNodeTypes["Image"] = "Image";
ASTNodeTypes["Code"] = "Code";
ASTNodeTypes["Delete"] = "Delete";
})(ASTNodeTypes = exports.ASTNodeTypes || (exports.ASTNodeTypes = {}));
//# sourceMappingURL=index.js.map
import SourceCode from "./source-code";
import { TxtNode } from "@textlint/ast-node-types";
import { ASTNodeTypes, TxtNode } from "@textlint/ast-node-types";
import RuleError from "./rule-error";

@@ -48,24 +48,3 @@ import { ShouldIgnoreFunction } from "../task/textlint-core-task";

*/
readonly Syntax: {
Document: string;
Paragraph: string;
BlockQuote: string;
ListItem: string;
List: string;
Header: string;
CodeBlock: string;
HtmlBlock: string;
ReferenceDef: string;
HorizontalRule: string;
Comment: string;
Str: string;
Break: string;
Emphasis: string;
Strong: string;
Html: string;
Link: string;
Image: string;
Code: string;
Delete: string;
};
readonly Syntax: typeof ASTNodeTypes;
/**

@@ -72,0 +51,0 @@ * CustomError object

import { BaseRuleContext } from "./BaseRuleContext";
import { TxtNode } from "@textlint/ast-node-types";
import RuleFixer from "../fixer/rule-fixer";
import { TxtNode, ASTNodeTypes } from "@textlint/ast-node-types";
import RuleFixer, { IntermediateFixCommand } from "../fixer/rule-fixer";
import RuleError from "./rule-error";

@@ -29,6 +29,18 @@ import SourceCode from "./source-code";

}
/**
* Object version of RuleError
* It is un-document way
*
* report(node, {
* message: ""
* })
*/
export interface RuleReportedObject {
[index: string]: any;
line?: number;
column?: number;
index?: number;
fix?: IntermediateFixCommand;
message: string;
severity?: number;
[index: string]: any;
}

@@ -51,26 +63,5 @@ export default class RuleContext implements BaseRuleContext {

* Node's type values
* @type {TextLintNodeType}
* @type {ASTNodeTypes}
*/
readonly Syntax: {
Document: string;
Paragraph: string;
BlockQuote: string;
ListItem: string;
List: string;
Header: string;
CodeBlock: string;
HtmlBlock: string;
ReferenceDef: string;
HorizontalRule: string;
Comment: string;
Str: string;
Break: string;
Emphasis: string;
Strong: string;
Html: string;
Link: string;
Image: string;
Code: string;
Delete: string;
};
readonly Syntax: typeof ASTNodeTypes;
/**

@@ -77,0 +68,0 @@ * CustomError object

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

if (ruleError instanceof rule_error_1.default) {
// FIXME: severity is internal API
// severity come from `.textlintrc` option like `{ "<rule-name>" : { serverity: "warning" } } `
_this._report({ ruleId: _this._ruleId, node: node, severity: _this._severity, ruleError: ruleError });
}
else {
var level = ruleError.severity || SeverityLevel_1.default.error;
_this._report({ ruleId: _this._ruleId, node: node, severity: level, ruleError: ruleError });
var ruleReportedObject = ruleError;
// severity come from report arguments like `report(node, { severity: 1 })`
var level = ruleReportedObject.severity || SeverityLevel_1.default.error;
_this._report({ ruleId: _this._ruleId, node: node, severity: level, ruleError: ruleReportedObject });
}

@@ -90,3 +92,3 @@ };

* Node's type values
* @type {TextLintNodeType}
* @type {ASTNodeTypes}
*/

@@ -93,0 +95,0 @@ get: function () {

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

import { TextlintFixCommand } from "../textlint-kernel-interface";
import { IntermediateFixCommand } from "../fixer/rule-fixer";
export interface RuleErrorPadding {

@@ -6,15 +6,15 @@ line?: number;

index?: number;
fix?: TextlintFixCommand;
fix?: IntermediateFixCommand;
}
export default class RuleError {
message: string;
private line?;
private column?;
private index?;
private fix?;
line?: number;
column?: number;
index?: number;
fix?: IntermediateFixCommand;
/**
* RuleError is like Error object.
* It's used for adding to TextlintResult.
* @param {string} message error message should start with lowercase letter
* @param {RuleError~Padding|number} [paddingLocation] - the object has padding {line, column} for actual error reason
* @param message error message should start with lowercase letter
* @param [paddingLocation] - the object has padding {line, column} for actual error reason
* @constructor

@@ -21,0 +21,0 @@ */

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

* It's used for adding to TextlintResult.
* @param {string} message error message should start with lowercase letter
* @param {RuleError~Padding|number} [paddingLocation] - the object has padding {line, column} for actual error reason
* @param message error message should start with lowercase letter
* @param [paddingLocation] - the object has padding {line, column} for actual error reason
* @constructor

@@ -12,0 +12,0 @@ */

import { TxtNode } from "@textlint/ast-node-types";
import { ASTNodeTypes } from "@textlint/ast-node-types";
export interface SourceCodePosition {

@@ -40,24 +41,3 @@ line: number;

*/
getSyntax(): {
Document: string;
Paragraph: string;
BlockQuote: string;
ListItem: string;
List: string;
Header: string;
CodeBlock: string;
HtmlBlock: string;
ReferenceDef: string;
HorizontalRule: string;
Comment: string;
Str: string;
Break: string;
Emphasis: string;
Strong: string;
Html: string;
Link: string;
Image: string;
Code: string;
Delete: string;
};
getSyntax(): typeof ASTNodeTypes;
/**

@@ -64,0 +44,0 @@ * get filePath

import SourceCode from "./source-code";
import RuleError, { RuleErrorPadding } from "./rule-error";
import { TextlintMessage } from "../textlint-kernel-interface";
import { TxtNode } from "@textlint/ast-node-types";
import { ReportArgs } from "../task/textlint-core-task";
import { TextlintFixCommand } from "@textlint/kernel";
/**

@@ -27,6 +28,10 @@ * @typedef {Object} ReportMessage

* adjust node's location with error's padding location.
* @param {ReportMessage} reportedMessage
* @param {ReportMessage} reportArgs
* @returns {{line: number, column: number, fix?: FixCommand}}
*/
adjust(reportedMessage: any): any;
adjust(reportArgs: ReportArgs): {
line: number;
column: number;
fix?: TextlintFixCommand;
};
_adjustLoc(node: any, padding: RuleErrorPadding, _paddingIndex?: number): {

@@ -40,7 +45,7 @@ line: any;

* @param {TxtNode} node
* @param {TextlintMessage} paddingMessage
* @param {RuleError} ruleErrorObject
* @returns {FixCommand|Object}
* @private
*/
_adjustFix(node: TxtNode, paddingMessage: TextlintMessage): {} | {
_adjustFix(node: TxtNode, ruleErrorObject: RuleError): {} | {
fix: {

@@ -47,0 +52,0 @@ range: number[];

@@ -17,7 +17,7 @@ // LICENSE : MIT

* adjust node's location with error's padding location.
* @param {ReportMessage} reportedMessage
* @param {ReportMessage} reportArgs
* @returns {{line: number, column: number, fix?: FixCommand}}
*/
SourceLocation.prototype.adjust = function (reportedMessage) {
var node = reportedMessage.node, ruleError = reportedMessage.ruleError, ruleId = reportedMessage.ruleId;
SourceLocation.prototype.adjust = function (reportArgs) {
var node = reportArgs.node, ruleError = reportArgs.ruleError, ruleId = reportArgs.ruleId;
var errorPrefix = "[" + ruleId + "]" || "";

@@ -39,3 +39,3 @@ var padding = ruleError;

}
// Not use {column, line} with {index}
// When either one of {column, line} or {index} is not used, throw error
if ((padding.line !== undefined || padding.column !== undefined) && padding.index !== undefined) {

@@ -124,15 +124,15 @@ // Introduced textlint 5.6

* @param {TxtNode} node
* @param {TextlintMessage} paddingMessage
* @param {RuleError} ruleErrorObject
* @returns {FixCommand|Object}
* @private
*/
SourceLocation.prototype._adjustFix = function (node, paddingMessage) {
SourceLocation.prototype._adjustFix = function (node, ruleErrorObject) {
var nodeRange = node.range;
// if not found `fix`, return empty object
if (paddingMessage.fix === undefined) {
if (ruleErrorObject.fix === undefined) {
return {};
}
assert(typeof paddingMessage.fix === "object", "fix should be FixCommand object");
assert(typeof ruleErrorObject.fix === "object", "fix should be FixCommand object");
// if absolute position return self
if (paddingMessage.fix.isAbsolute) {
if (ruleErrorObject.fix.isAbsolute) {
return {

@@ -142,4 +142,4 @@ // remove other property that is not related `fix`

fix: {
range: paddingMessage.fix.range,
text: paddingMessage.fix.text
range: ruleErrorObject.fix.range,
text: ruleErrorObject.fix.text
}

@@ -152,4 +152,4 @@ };

fix: {
range: [nodeRange[0] + paddingMessage.fix.range[0], nodeRange[0] + paddingMessage.fix.range[1]],
text: paddingMessage.fix.text
range: [nodeRange[0] + ruleErrorObject.fix.range[0], nodeRange[0] + ruleErrorObject.fix.range[1]],
text: ruleErrorObject.fix.text
}

@@ -156,0 +156,0 @@ };

import { TxtNode } from "@textlint/ast-node-types";
import { SourceCodeRange } from "../core/source-code";
/**
* Fix Command object has `range` and `text`.
* `IntermediateFixCommand` has also `isAbsolute` flag value.
*/
export declare class IntermediateFixCommand {
text: string;
range: [number, number];
isAbsolute: boolean;
}
/**
* Creates code fixing commands for rules.

@@ -16,3 +25,3 @@ * It create command for fixing texts.

* @param {string} text The text to insert.
* @returns {FixCommand} The fix command.
* @returns {IntermediateFixCommand} The fix command.
*/

@@ -31,3 +40,3 @@ insertTextAfter(node: TxtNode, text: string): {

* @param {string} text The text to insert.
* @returns {FixCommand} The fix command.
* @returns {IntermediateFixCommand} The fix command.
*/

@@ -44,3 +53,3 @@ insertTextAfterRange(range: SourceCodeRange, text: string): {

* @param {string} text The text to insert.
* @returns {FixCommand} The fix command.
* @returns {IntermediateFixCommand} The fix command.
*/

@@ -59,3 +68,3 @@ insertTextBefore(node: TxtNode, text: string): {

* @param {string} text The text to insert.
* @returns {FixCommand} The fix command.
* @returns {IntermediateFixCommand} The fix command.
*/

@@ -72,3 +81,3 @@ insertTextBeforeRange(range: SourceCodeRange, text: string): {

* @param {string} text The text to insert.
* @returns {FixCommand} The fix command.
* @returns {IntermediateFixCommand} The fix command.
*/

@@ -87,3 +96,3 @@ replaceText(node: TxtNode, text: string): {

* @param {string} text The text to insert.
* @returns {FixCommand} The fix command.
* @returns {IntermediateFixCommand} The fix command.
*/

@@ -99,3 +108,3 @@ replaceTextRange(range: SourceCodeRange, text: string): {

* @param {TxtNode} node The node or token to remove.
* @returns {FixCommand} The fix command.
* @returns {IntermediateFixCommand} The fix command.
*/

@@ -113,3 +122,3 @@ remove(node: TxtNode): {

* The `range` should be **relative** value from reported node.
* @returns {FixCommand} The fix command.
* @returns {IntermediateFixCommand} The fix command.
*/

@@ -116,0 +125,0 @@ removeRange(range: SourceCodeRange): {

@@ -6,7 +6,10 @@ "use strict";

* Fix Command object has `range` and `text`.
* @typedef {Object} FixCommand
* @property {number[]} range range is an array of numbers : [start, end]
* @property {string} text text is replace value.
* @property {boolean} isAbsolute if `range` is relative, should be `false`
* `IntermediateFixCommand` has also `isAbsolute` flag value.
*/
var IntermediateFixCommand = /** @class */ (function () {
function IntermediateFixCommand() {
}
return IntermediateFixCommand;
}());
exports.IntermediateFixCommand = IntermediateFixCommand;
/**

@@ -16,3 +19,3 @@ * Creates a fix command that inserts text at the specified index in the source text.

* @param {string} text The text to insert.
* @returns {FixCommand} The fix command.
* @returns {IntermediateFixCommand} The fix command.
* @private

@@ -32,3 +35,3 @@ */

* @param {string} text The text to insert.
* @returns {FixCommand} The fix command.
* @returns {IntermediateFixCommand} The fix command.
* @private

@@ -59,3 +62,3 @@ */

* @param {string} text The text to insert.
* @returns {FixCommand} The fix command.
* @returns {IntermediateFixCommand} The fix command.
*/

@@ -72,3 +75,3 @@ RuleFixer.prototype.insertTextAfter = function (node, text) {

* @param {string} text The text to insert.
* @returns {FixCommand} The fix command.
* @returns {IntermediateFixCommand} The fix command.
*/

@@ -83,3 +86,3 @@ RuleFixer.prototype.insertTextAfterRange = function (range, text) {

* @param {string} text The text to insert.
* @returns {FixCommand} The fix command.
* @returns {IntermediateFixCommand} The fix command.
*/

@@ -96,3 +99,3 @@ RuleFixer.prototype.insertTextBefore = function (node, text) {

* @param {string} text The text to insert.
* @returns {FixCommand} The fix command.
* @returns {IntermediateFixCommand} The fix command.
*/

@@ -107,3 +110,3 @@ RuleFixer.prototype.insertTextBeforeRange = function (range, text) {

* @param {string} text The text to insert.
* @returns {FixCommand} The fix command.
* @returns {IntermediateFixCommand} The fix command.
*/

@@ -124,3 +127,3 @@ RuleFixer.prototype.replaceText = function (node, text) {

* @param {string} text The text to insert.
* @returns {FixCommand} The fix command.
* @returns {IntermediateFixCommand} The fix command.
*/

@@ -138,3 +141,3 @@ RuleFixer.prototype.replaceTextRange = function (range, text) {

* @param {TxtNode} node The node or token to remove.
* @returns {FixCommand} The fix command.
* @returns {IntermediateFixCommand} The fix command.
*/

@@ -150,3 +153,3 @@ RuleFixer.prototype.remove = function (node) {

* The `range` should be **relative** value from reported node.
* @returns {FixCommand} The fix command.
* @returns {IntermediateFixCommand} The fix command.
*/

@@ -153,0 +156,0 @@ RuleFixer.prototype.removeRange = function (range) {

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

* push new RuleError to results
* @param {ReportMessage} reportedMessage
* @param {ReportMessage} reportArgs
*/
var reportFunction = function (reportedMessage) {
var ruleId = reportedMessage.ruleId, severity = reportedMessage.severity, ruleError = reportedMessage.ruleError;
var reportFunction = function (reportArgs) {
var ruleId = reportArgs.ruleId, severity = reportArgs.severity, ruleError = reportArgs.ruleError;
debug("%s pushReport %s", ruleId, ruleError);
var _a = sourceLocation.adjust(reportedMessage), line = _a.line, column = _a.column, fix = _a.fix;
var _a = sourceLocation.adjust(reportArgs), line = _a.line, column = _a.column, fix = _a.fix;
var index = sourceCode.positionToIndex({ line: line, column: column });

@@ -91,0 +91,0 @@ // add TextLintMessage

@@ -109,3 +109,2 @@ import { TxtNode, TxtNodeType } from "@textlint/ast-node-types";

range: [number, number];
isAbsolute: boolean;
}

@@ -121,3 +120,3 @@ export declare class TextlintMessage {

index: number;
severity?: number;
severity: number;
}

@@ -124,0 +123,0 @@ export interface TextlintResult {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// "range" is replaced by "text"
// "range" will be replaced by "text"
var TextlintFixCommand = /** @class */ (function () {

@@ -5,0 +5,0 @@ function TextlintFixCommand() {

@@ -13,3 +13,3 @@ {

"name": "@textlint/kernel",
"version": "2.0.2",
"version": "2.0.3",
"description": "textlint kernel is core logic by pure JavaScript.",

@@ -46,3 +46,3 @@ "main": "lib/kernel/src/index.js",

"shelljs": "^0.7.7",
"textlint-plugin-markdown": "^4.0.2",
"textlint-plugin-markdown": "^4.0.4",
"ts-node": "^3.3.0",

@@ -52,3 +52,3 @@ "typescript": "~2.6.1"

"dependencies": {
"@textlint/ast-node-types": "^3.0.1",
"@textlint/ast-node-types": "^4.0.0",
"@textlint/feature-flag": "^3.0.1",

@@ -55,0 +55,0 @@ "@types/bluebird": "^3.5.18",

// LICENSE : MIT
"use strict";
import SourceCode from "./source-code";
import { TxtNode } from "@textlint/ast-node-types";
import { ASTNodeTypes, TxtNode } from "@textlint/ast-node-types";
import RuleError from "./rule-error";

@@ -64,3 +64,3 @@ import { ShouldIgnoreFunction } from "../task/textlint-core-task";

*/
get Syntax() {
get Syntax(): typeof ASTNodeTypes {
return this._sourceCode.getSyntax();

@@ -67,0 +67,0 @@ }

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

const assert = require("assert");
import { TxtNode } from "@textlint/ast-node-types";
import RuleFixer from "../fixer/rule-fixer";
import { TxtNode, ASTNodeTypes } from "@textlint/ast-node-types";
import RuleFixer, { IntermediateFixCommand } from "../fixer/rule-fixer";
import RuleError from "./rule-error";

@@ -41,7 +41,19 @@ import SeverityLevel from "../shared/type/SeverityLevel";

/**
* Object version of RuleError
* It is un-document way
*
* report(node, {
* message: ""
* })
*/
export interface RuleReportedObject {
[index: string]: any;
line?: number;
column?: number;
index?: number;
fix?: IntermediateFixCommand;
message: string;
severity?: number;
[index: string]: any;
}

@@ -80,5 +92,5 @@

* Node's type values
* @type {TextLintNodeType}
* @type {ASTNodeTypes}
*/
get Syntax() {
get Syntax(): typeof ASTNodeTypes {
return this._sourceCode.getSyntax();

@@ -110,7 +122,9 @@ }

if (ruleError instanceof RuleError) {
// FIXME: severity is internal API
// severity come from `.textlintrc` option like `{ "<rule-name>" : { serverity: "warning" } } `
this._report({ ruleId: this._ruleId, node, severity: this._severity, ruleError });
} else {
const level = ruleError.severity || SeverityLevel.error;
this._report({ ruleId: this._ruleId, node, severity: level, ruleError });
const ruleReportedObject: RuleReportedObject = ruleError;
// severity come from report arguments like `report(node, { severity: 1 })`
const level = ruleReportedObject.severity || SeverityLevel.error;
this._report({ ruleId: this._ruleId, node, severity: level, ruleError: ruleReportedObject });
}

@@ -117,0 +131,0 @@ };

// LICENSE : MIT
"use strict";
import { TextlintFixCommand } from "../textlint-kernel-interface";
import { IntermediateFixCommand } from "../fixer/rule-fixer";

@@ -9,3 +9,3 @@ export interface RuleErrorPadding {

index?: number;
fix?: TextlintFixCommand;
fix?: IntermediateFixCommand;
}

@@ -15,6 +15,6 @@

public message: string;
private line?: number;
private column?: number;
private index?: number;
private fix?: TextlintFixCommand;
public line?: number;
public column?: number;
public index?: number;
public fix?: IntermediateFixCommand;

@@ -24,4 +24,4 @@ /**

* It's used for adding to TextlintResult.
* @param {string} message error message should start with lowercase letter
* @param {RuleError~Padding|number} [paddingLocation] - the object has padding {line, column} for actual error reason
* @param message error message should start with lowercase letter
* @param [paddingLocation] - the object has padding {line, column} for actual error reason
* @constructor

@@ -28,0 +28,0 @@ */

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

import RuleError, { RuleErrorPadding } from "./rule-error";
import { TextlintMessage } from "../textlint-kernel-interface";
import { TxtNode } from "@textlint/ast-node-types";
import { ReportArgs } from "../task/textlint-core-task";
import { TextlintFixCommand } from "@textlint/kernel";

@@ -40,7 +41,7 @@ const assert = require("assert");

* adjust node's location with error's padding location.
* @param {ReportMessage} reportedMessage
* @param {ReportMessage} reportArgs
* @returns {{line: number, column: number, fix?: FixCommand}}
*/
adjust(reportedMessage: any) {
const { node, ruleError, ruleId } = reportedMessage;
adjust(reportArgs: ReportArgs): { line: number; column: number; fix?: TextlintFixCommand } {
const { node, ruleError, ruleId } = reportArgs;
const errorPrefix = `[${ruleId}]` || "";

@@ -84,3 +85,3 @@ const padding = ruleError;

// Not use {column, line} with {index}
// When either one of {column, line} or {index} is not used, throw error
if ((padding.line !== undefined || padding.column !== undefined) && padding.index !== undefined) {

@@ -186,15 +187,15 @@ // Introduced textlint 5.6

* @param {TxtNode} node
* @param {TextlintMessage} paddingMessage
* @param {RuleError} ruleErrorObject
* @returns {FixCommand|Object}
* @private
*/
_adjustFix(node: TxtNode, paddingMessage: TextlintMessage) {
_adjustFix(node: TxtNode, ruleErrorObject: RuleError) {
const nodeRange = node.range;
// if not found `fix`, return empty object
if (paddingMessage.fix === undefined) {
if (ruleErrorObject.fix === undefined) {
return {};
}
assert(typeof paddingMessage.fix === "object", "fix should be FixCommand object");
assert(typeof ruleErrorObject.fix === "object", "fix should be FixCommand object");
// if absolute position return self
if (paddingMessage.fix.isAbsolute) {
if (ruleErrorObject.fix.isAbsolute) {
return {

@@ -204,4 +205,4 @@ // remove other property that is not related `fix`

fix: {
range: paddingMessage.fix.range,
text: paddingMessage.fix.text
range: ruleErrorObject.fix.range,
text: ruleErrorObject.fix.text
}

@@ -214,4 +215,4 @@ };

fix: {
range: [nodeRange[0] + paddingMessage.fix.range[0], nodeRange[0] + paddingMessage.fix.range[1]],
text: paddingMessage.fix.text
range: [nodeRange[0] + ruleErrorObject.fix.range[0], nodeRange[0] + ruleErrorObject.fix.range[1]],
text: ruleErrorObject.fix.text
}

@@ -218,0 +219,0 @@ };

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

* Fix Command object has `range` and `text`.
* @typedef {Object} FixCommand
* @property {number[]} range range is an array of numbers : [start, end]
* @property {string} text text is replace value.
* @property {boolean} isAbsolute if `range` is relative, should be `false`
* `IntermediateFixCommand` has also `isAbsolute` flag value.
*/
export class IntermediateFixCommand {
text: string;
range: [number, number];
isAbsolute: boolean;
}
/**

@@ -17,3 +20,3 @@ * Creates a fix command that inserts text at the specified index in the source text.

* @param {string} text The text to insert.
* @returns {FixCommand} The fix command.
* @returns {IntermediateFixCommand} The fix command.
* @private

@@ -34,3 +37,3 @@ */

* @param {string} text The text to insert.
* @returns {FixCommand} The fix command.
* @returns {IntermediateFixCommand} The fix command.
* @private

@@ -60,3 +63,3 @@ */

* @param {string} text The text to insert.
* @returns {FixCommand} The fix command.
* @returns {IntermediateFixCommand} The fix command.
*/

@@ -74,3 +77,3 @@ insertTextAfter(node: TxtNode, text: string) {

* @param {string} text The text to insert.
* @returns {FixCommand} The fix command.
* @returns {IntermediateFixCommand} The fix command.
*/

@@ -86,3 +89,3 @@ insertTextAfterRange(range: SourceCodeRange, text: string) {

* @param {string} text The text to insert.
* @returns {FixCommand} The fix command.
* @returns {IntermediateFixCommand} The fix command.
*/

@@ -100,3 +103,3 @@ insertTextBefore(node: TxtNode, text: string) {

* @param {string} text The text to insert.
* @returns {FixCommand} The fix command.
* @returns {IntermediateFixCommand} The fix command.
*/

@@ -112,3 +115,3 @@ insertTextBeforeRange(range: SourceCodeRange, text: string) {

* @param {string} text The text to insert.
* @returns {FixCommand} The fix command.
* @returns {IntermediateFixCommand} The fix command.
*/

@@ -130,3 +133,3 @@ replaceText(node: TxtNode, text: string) {

* @param {string} text The text to insert.
* @returns {FixCommand} The fix command.
* @returns {IntermediateFixCommand} The fix command.
*/

@@ -145,3 +148,3 @@ replaceTextRange(range: SourceCodeRange, text: string) {

* @param {TxtNode} node The node or token to remove.
* @returns {FixCommand} The fix command.
* @returns {IntermediateFixCommand} The fix command.
*/

@@ -158,3 +161,3 @@ remove(node: TxtNode) {

* The `range` should be **relative** value from reported node.
* @returns {FixCommand} The fix command.
* @returns {IntermediateFixCommand} The fix command.
*/

@@ -161,0 +164,0 @@ removeRange(range: SourceCodeRange) {

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

* push new RuleError to results
* @param {ReportMessage} reportedMessage
* @param {ReportMessage} reportArgs
*/
const reportFunction = (reportedMessage: ReportArgs) => {
const { ruleId, severity, ruleError } = reportedMessage;
const reportFunction = (reportArgs: ReportArgs) => {
const { ruleId, severity, ruleError } = reportArgs;
debug("%s pushReport %s", ruleId, ruleError);
const { line, column, fix } = sourceLocation.adjust(reportedMessage);
const { line, column, fix } = sourceLocation.adjust(reportArgs);
const index = sourceCode.positionToIndex({ line, column });

@@ -147,0 +147,0 @@ // add TextLintMessage

@@ -164,7 +164,6 @@ // rule config

// "range" is replaced by "text"
// "range" will be replaced by "text"
export class TextlintFixCommand {
text: string;
range: [number, number];
isAbsolute: boolean;
}

@@ -191,3 +190,3 @@

// See src/shared/type/SeverityLevel.js
severity?: number;
severity: number;
}

@@ -194,0 +193,0 @@

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