@textlint/kernel
Advanced tools
Comparing version 0.0.0 to 0.1.0
@@ -53,4 +53,4 @@ // LICENSE : MIT | ||
* @param {Config} config | ||
* @param {TextlintKernelRule[]} rules | ||
* @param {TextlintKernelFilterRule[]} filterRules | ||
* @param {TextlintKernelRule[]} [rules] | ||
* @param {TextlintKernelFilterRule[]} [filterRules] | ||
* @param {SourceCode} sourceCode | ||
@@ -67,7 +67,9 @@ * @returns {Promise.<TextLintFixResult>} | ||
var config = _ref.config, | ||
rules = _ref.rules, | ||
filterRules = _ref.filterRules, | ||
_ref$rules = _ref.rules, | ||
rules = _ref$rules === undefined ? [] : _ref$rules, | ||
_ref$filterRules = _ref.filterRules, | ||
filterRules = _ref$filterRules === undefined ? [] : _ref$filterRules, | ||
sourceCode = _ref.sourceCode; | ||
(0, _assert2.default)(config && rules && sourceCode); | ||
(0, _assert2.default)(config && Array.isArray(rules) && Array.isArray(filterRules) && sourceCode); | ||
@@ -74,0 +76,0 @@ var _processor$processor = this.processor.processor(sourceCode.ext), |
@@ -41,4 +41,4 @@ // LICENSE : MIT | ||
* @param {Config} config | ||
* @param {TextlintKernelRule[]} rules | ||
* @param {TextlintKernelFilterRule[]} filterRules | ||
* @param {TextlintKernelRule[]} [rules] | ||
* @param {TextlintKernelFilterRule[]} [filterRules] | ||
* @param {SourceCode} sourceCode | ||
@@ -55,7 +55,9 @@ * @returns {Promise.<TextLintResult>} | ||
var config = _ref.config, | ||
rules = _ref.rules, | ||
filterRules = _ref.filterRules, | ||
_ref$rules = _ref.rules, | ||
rules = _ref$rules === undefined ? [] : _ref$rules, | ||
_ref$filterRules = _ref.filterRules, | ||
filterRules = _ref$filterRules === undefined ? [] : _ref$filterRules, | ||
sourceCode = _ref.sourceCode; | ||
(0, _assert2.default)(config && rules && sourceCode); | ||
(0, _assert2.default)(config && Array.isArray(rules) && Array.isArray(filterRules) && sourceCode); | ||
@@ -62,0 +64,0 @@ var _processor$processor = this.processor.processor(sourceCode.ext), |
@@ -5,5 +5,3 @@ export interface TextlintKernelPlugin { | ||
// plugin processor instance | ||
plugin: Object | { | ||
Processor: Object | ||
}; | ||
plugin: any; | ||
// plugin options | ||
@@ -18,6 +16,6 @@ // TODO: It is not implemented | ||
// rule module instance | ||
rule: Function | Object; | ||
rule: any; | ||
// rule options | ||
// Often rule option is written in .textlintrc | ||
options?: Object | boolean; | ||
options?: any | boolean; | ||
} | ||
@@ -29,6 +27,6 @@ | ||
// filter rule module instance | ||
rule: Function | Object; | ||
rule: any; | ||
// filter rule options | ||
// Often rule option is written in .textlintrc | ||
options?: Object | boolean; | ||
options?: any | boolean; | ||
} | ||
@@ -102,3 +100,3 @@ | ||
export class TextlintKernel { | ||
constructor(config: Object); | ||
constructor(config?: Object); | ||
@@ -105,0 +103,0 @@ lintText(text: string, options: TextlintKernelOptions): Promise<TextLintResult>; |
@@ -48,2 +48,5 @@ // MIT © 2017 azu | ||
var assert = require("assert"); | ||
var Ajv = require("ajv"); | ||
var ajv = new Ajv(); | ||
var TextlintKernelOptionsSchema = require("./TextlintKernelOptions.json"); | ||
// sequence | ||
@@ -105,2 +108,6 @@ | ||
var TextlintKernel = exports.TextlintKernel = function () { | ||
/** | ||
* TODO: THIS | ||
* @param config | ||
*/ | ||
function TextlintKernel() { | ||
@@ -129,3 +136,3 @@ var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
* @param {string} text | ||
* @param {TextlintKernelOptions} options linting options | ||
* @param {Object} options linting options | ||
* @returns {Promise.<TextLintResult>} | ||
@@ -138,2 +145,6 @@ */ | ||
value: function lintText(text, options) { | ||
var valid = ajv.validate(TextlintKernelOptionsSchema, options); | ||
if (!valid) { | ||
return Promise.reject(new Error("options is invalid. Please check document.\nErrors: " + JSON.stringify(ajv.errors, null, 4) + "\nActual: " + JSON.stringify(options, null, 4) + "\n")); | ||
} | ||
var ext = options.ext; | ||
@@ -153,3 +164,3 @@ var plugin = findPluginWithExt(options.plugins, ext); | ||
* @param {string} text | ||
* @param {TextlintKernelOptions} options lint options | ||
* @param {Object} options lint options | ||
* @returns {Promise.<TextLintFixResult>} | ||
@@ -161,2 +172,6 @@ */ | ||
value: function fixText(text, options) { | ||
var valid = ajv.validate(TextlintKernelOptionsSchema, options); | ||
if (!valid) { | ||
return Promise.reject(new Error("options is invalid. Please check document.\nErrors: " + JSON.stringify(ajv.errors, null, 4) + "\nActual: " + JSON.stringify(options, null, 4) + "\n")); | ||
} | ||
var ext = options.ext; | ||
@@ -180,3 +195,3 @@ var plugin = findPluginWithExt(options.plugins, ext); | ||
* @param {string} text | ||
* @param {TextlintKernelOptions} options | ||
* @param {Object} options | ||
* @returns {Promise.<TextLintResult>} | ||
@@ -183,0 +198,0 @@ * @private |
@@ -13,3 +13,3 @@ { | ||
"name": "@textlint/kernel", | ||
"version": "0.0.0", | ||
"version": "0.1.0", | ||
"description": "textlint kernel is core logic by pure JavaScript.", | ||
@@ -45,7 +45,10 @@ "main": "lib/textlint-kernel.js", | ||
"power-assert": "^1.4.2", | ||
"shelljs": "^0.7.7" | ||
"shelljs": "^0.7.7", | ||
"textlint-plugin-markdown": "^2.0.3", | ||
"typescript-json-schema": "^0.11.0" | ||
}, | ||
"dependencies": { | ||
"@textlint/ast-node-types": "^1.1.2", | ||
"@textlint/feature-flag": "1.0.0", | ||
"@textlint/feature-flag": "^1.0.1", | ||
"ajv": "^4", | ||
"bluebird": "^3.5.0", | ||
@@ -55,2 +58,3 @@ "carrack": "^0.5.0", | ||
"deep-equal": "^1.0.1", | ||
"is-my-json-valid": "^2.16.0", | ||
"map-like": "^1.1.2", | ||
@@ -57,0 +61,0 @@ "object-assign": "^4.1.1", |
@@ -5,2 +5,6 @@ # @textlint/kernel | ||
This module is low layer of textlint. | ||
No plugin, No rule, No filter rule by default. | ||
## Install | ||
@@ -14,3 +18,26 @@ | ||
- [ ] Write usage instructions | ||
```js | ||
import TextlintKernel from "@textlint/kernel"; | ||
const kernel = new TextlintKernel(); | ||
const options = { | ||
filePath: "/path/to/file.md", | ||
ext: ".md", | ||
plugins: [ | ||
{ | ||
pluginId: "markdown", | ||
plugin: require("textlint-plugin-markdown") | ||
} | ||
], | ||
rules: [ | ||
{ | ||
ruleId: "no-todo", | ||
rule: require("textlint-rule-no-todo") | ||
} | ||
] | ||
}; | ||
kernel.lintText("TODO: text", options).then(result => { | ||
assert.ok(typeof result.filePath === "string"); | ||
assert.ok(result.messages.length === 1); | ||
}); | ||
``` | ||
@@ -17,0 +44,0 @@ ## Changelog |
@@ -24,9 +24,9 @@ // LICENSE : MIT | ||
* @param {Config} config | ||
* @param {TextlintKernelRule[]} rules | ||
* @param {TextlintKernelFilterRule[]} filterRules | ||
* @param {TextlintKernelRule[]} [rules] | ||
* @param {TextlintKernelFilterRule[]} [filterRules] | ||
* @param {SourceCode} sourceCode | ||
* @returns {Promise.<TextLintFixResult>} | ||
*/ | ||
process({ config, rules, filterRules, sourceCode }) { | ||
assert(config && rules && sourceCode); | ||
process({ config, rules = [], filterRules = [], sourceCode }) { | ||
assert(config && Array.isArray(rules) && Array.isArray(filterRules) && sourceCode); | ||
const { preProcess, postProcess } = this.processor.processor(sourceCode.ext); | ||
@@ -33,0 +33,0 @@ // messages |
@@ -6,2 +6,3 @@ // LICENSE : MIT | ||
import TaskRunner from "../task/task-runner"; | ||
export default class LinterProcessor { | ||
@@ -20,10 +21,10 @@ /** | ||
* @param {Config} config | ||
* @param {TextlintKernelRule[]} rules | ||
* @param {TextlintKernelFilterRule[]} filterRules | ||
* @param {TextlintKernelRule[]} [rules] | ||
* @param {TextlintKernelFilterRule[]} [filterRules] | ||
* @param {SourceCode} sourceCode | ||
* @returns {Promise.<TextLintResult>} | ||
*/ | ||
process({config, rules, filterRules, sourceCode}) { | ||
assert(config && rules && sourceCode); | ||
const {preProcess, postProcess} = this.processor.processor(sourceCode.ext); | ||
process({ config, rules = [], filterRules = [], sourceCode }) { | ||
assert(config && Array.isArray(rules) && Array.isArray(filterRules) && sourceCode); | ||
const { preProcess, postProcess } = this.processor.processor(sourceCode.ext); | ||
assert(typeof preProcess === "function" && typeof postProcess === "function", | ||
@@ -30,0 +31,0 @@ "processor should implement {preProcess, postProcess}"); |
@@ -5,5 +5,3 @@ export interface TextlintKernelPlugin { | ||
// plugin processor instance | ||
plugin: Object | { | ||
Processor: Object | ||
}; | ||
plugin: any; | ||
// plugin options | ||
@@ -18,6 +16,6 @@ // TODO: It is not implemented | ||
// rule module instance | ||
rule: Function | Object; | ||
rule: any; | ||
// rule options | ||
// Often rule option is written in .textlintrc | ||
options?: Object | boolean; | ||
options?: any | boolean; | ||
} | ||
@@ -29,6 +27,6 @@ | ||
// filter rule module instance | ||
rule: Function | Object; | ||
rule: any; | ||
// filter rule options | ||
// Often rule option is written in .textlintrc | ||
options?: Object | boolean; | ||
options?: any | boolean; | ||
} | ||
@@ -102,3 +100,3 @@ | ||
export class TextlintKernel { | ||
constructor(config: Object); | ||
constructor(config?: Object); | ||
@@ -105,0 +103,0 @@ lintText(text: string, options: TextlintKernelOptions): Promise<TextLintResult>; |
// MIT © 2017 azu | ||
"use strict"; | ||
const assert = require("assert"); | ||
const Ajv = require("ajv"); | ||
const ajv = new Ajv(); | ||
const TextlintKernelOptionsSchema = require("./TextlintKernelOptions.json"); | ||
import SourceCode from "./core/source-code"; | ||
@@ -62,2 +65,6 @@ // sequence | ||
export class TextlintKernel { | ||
/** | ||
* TODO: THIS | ||
* @param config | ||
*/ | ||
constructor(config = {}) { | ||
@@ -82,6 +89,13 @@ // this.config often is undefined. | ||
* @param {string} text | ||
* @param {TextlintKernelOptions} options linting options | ||
* @param {Object} options linting options | ||
* @returns {Promise.<TextLintResult>} | ||
*/ | ||
lintText(text, options) { | ||
const valid = ajv.validate(TextlintKernelOptionsSchema, options); | ||
if (!valid) { | ||
return Promise.reject(new Error(`options is invalid. Please check document. | ||
Errors: ${JSON.stringify(ajv.errors, null, 4)} | ||
Actual: ${JSON.stringify(options, null, 4)} | ||
`)); | ||
} | ||
const ext = options.ext; | ||
@@ -101,6 +115,13 @@ const plugin = findPluginWithExt(options.plugins, ext); | ||
* @param {string} text | ||
* @param {TextlintKernelOptions} options lint options | ||
* @param {Object} options lint options | ||
* @returns {Promise.<TextLintFixResult>} | ||
*/ | ||
fixText(text, options) { | ||
const valid = ajv.validate(TextlintKernelOptionsSchema, options); | ||
if (!valid) { | ||
return Promise.reject(new Error(`options is invalid. Please check document. | ||
Errors: ${JSON.stringify(ajv.errors, null, 4)} | ||
Actual: ${JSON.stringify(options, null, 4)} | ||
`)); | ||
} | ||
const ext = options.ext; | ||
@@ -125,3 +146,3 @@ const plugin = findPluginWithExt(options.plugins, ext); | ||
* @param {string} text | ||
* @param {TextlintKernelOptions} options | ||
* @param {Object} options | ||
* @returns {Promise.<TextLintResult>} | ||
@@ -128,0 +149,0 @@ * @private |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
291208
91
4494
72
12
12
+ Addedajv@^4
+ Addedis-my-json-valid@^2.16.0
+ Added@textlint/feature-flag@1.0.1(transitive)
+ Addedajv@4.11.8(transitive)
+ Addedco@4.6.0(transitive)
+ Addedgenerate-function@2.3.1(transitive)
+ Addedgenerate-object-property@1.2.0(transitive)
+ Addedis-arguments@1.2.0(transitive)
+ Addedis-date-object@1.1.0(transitive)
+ Addedis-my-ip-valid@1.0.1(transitive)
+ Addedis-my-json-valid@2.20.6(transitive)
+ Addedis-property@1.0.2(transitive)
+ Addedisarray@2.0.5(transitive)
+ Addedjson-stable-stringify@1.1.1(transitive)
+ Addedjsonify@0.0.1(transitive)
+ Addedjsonpointer@5.0.1(transitive)
+ Addedxtend@4.0.2(transitive)
- Removed@textlint/feature-flag@1.0.0(transitive)
- Removedis-arguments@1.1.1(transitive)
- Removedis-date-object@1.0.5(transitive)