@textlint/kernel
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -6,2 +6,13 @@ # Change Log | ||
<a name="0.2.0"></a> | ||
# [0.2.0](https://github.com/textlint/textlint/compare/@textlint/kernel@0.1.0...@textlint/kernel@0.2.0) (2017-05-21) | ||
### Features | ||
* **textlint-kernel:** add `configBaseDir` option (#295) ([85dad8a](https://github.com/textlint/textlint/commit/85dad8a)) | ||
<a name="0.1.0"></a> | ||
@@ -8,0 +19,0 @@ # 0.1.0 (2017-05-18) |
@@ -27,2 +27,4 @@ // LICENSE : MIT | ||
// instance for rule context | ||
var ruleFixer = new _ruleFixer2.default(); | ||
/** | ||
@@ -33,3 +35,2 @@ * This callback is displayed as a global member. | ||
*/ | ||
/** | ||
@@ -42,2 +43,3 @@ * Rule context object is passed to each rule as `context` | ||
* @param {Object|boolean} ruleOptions | ||
* @param {string} [configBaseDir] | ||
* @constructor | ||
@@ -50,5 +52,11 @@ */ | ||
textLintConfig = _ref.textLintConfig, | ||
ruleOptions = _ref.ruleOptions; | ||
ruleOptions = _ref.ruleOptions, | ||
configBaseDir = _ref.configBaseDir; | ||
Object.defineProperty(this, "id", { value: ruleId }); | ||
/** | ||
* Please use `getConfigBaseDir` insteadof it. | ||
* @see https://github.com/textlint/textlint/issues/294 | ||
* @deprecated | ||
*/ | ||
Object.defineProperty(this, "config", { value: textLintConfig }); | ||
@@ -86,3 +94,20 @@ var severity = (0, _ruleSeverity.getSeverity)(ruleOptions); | ||
this.getSource = sourceCode.getSource.bind(sourceCode); | ||
/** | ||
* get config base directory path | ||
* config base directory path often is the place of .textlintrc | ||
* | ||
* e.g.) /path/to/dir/.textlintrc | ||
* `getConfigBaseDir()` return `"/path/to/dir/"`. | ||
* | ||
* When using textlint as module, it is specified by `configBaseDir` | ||
* If not found the value, return undefined. | ||
* | ||
* You can use it for resolving relative path from config dir. | ||
* @returns {string|undefined} | ||
*/ | ||
this.getConfigBaseDir = function () { | ||
return configBaseDir; | ||
}; | ||
/** | ||
* CustomError object | ||
@@ -96,4 +121,4 @@ * @type {RuleError} | ||
*/ | ||
this.fixer = new _ruleFixer2.default(); | ||
this.fixer = ruleFixer; | ||
} | ||
//# sourceMappingURL=rule-context.js.map |
@@ -53,2 +53,3 @@ // LICENSE : MIT | ||
* @param {Config} config | ||
* @param {string} [configBaseDir] | ||
* @param {TextlintKernelRule[]} [rules] | ||
@@ -67,2 +68,3 @@ * @param {TextlintKernelFilterRule[]} [filterRules] | ||
var config = _ref.config, | ||
configBaseDir = _ref.configBaseDir, | ||
_ref$rules = _ref.rules, | ||
@@ -108,3 +110,4 @@ rules = _ref$rules === undefined ? [] : _ref$rules, | ||
filterRules: filterRules, | ||
sourceCode: newSourceCode | ||
sourceCode: newSourceCode, | ||
configBaseDir: configBaseDir | ||
}); | ||
@@ -111,0 +114,0 @@ |
@@ -41,2 +41,3 @@ // LICENSE : MIT | ||
* @param {Config} config | ||
* @param {string} [configBaseDir | ||
* @param {TextlintKernelRule[]} [rules] | ||
@@ -55,2 +56,3 @@ * @param {TextlintKernelFilterRule[]} [filterRules] | ||
var config = _ref.config, | ||
configBaseDir = _ref.configBaseDir, | ||
_ref$rules = _ref.rules, | ||
@@ -73,3 +75,4 @@ rules = _ref$rules === undefined ? [] : _ref$rules, | ||
filterRules: filterRules, | ||
sourceCode: sourceCode | ||
sourceCode: sourceCode, | ||
configBaseDir: configBaseDir | ||
}); | ||
@@ -76,0 +79,0 @@ return _taskRunner2.default.process(task).then(function (messages) { |
@@ -39,2 +39,3 @@ // LICENSE : MIT | ||
* @param {Config} config | ||
* @param {string} [configBaseDir] | ||
* @param {TextlintKernelRule} fixerRule rules has fixer | ||
@@ -46,2 +47,3 @@ * @param {TextlintKernelFilterRule[]} filterRules filter rules and config set | ||
var config = _ref.config, | ||
configBaseDir = _ref.configBaseDir, | ||
fixerRule = _ref.fixerRule, | ||
@@ -56,2 +58,3 @@ filterRules = _ref.filterRules, | ||
_this.config = config; | ||
_this.configBaseDir = configBaseDir; | ||
_this.fixerRule = fixerRule; | ||
@@ -87,3 +90,4 @@ _this.filterRules = filterRules; | ||
ignoreReport: ignoreReport, | ||
textLintConfig: textLintConfig | ||
textLintConfig: textLintConfig, | ||
configBaseDir: this.configBaseDir | ||
}); | ||
@@ -90,0 +94,0 @@ var ruleModule = (0, _ruleCreatorHelper.getFixer)(this.fixerRule.rule); |
@@ -39,2 +39,3 @@ // LICENSE : MIT | ||
* @param {Config} config | ||
* @param {string} [configBaseDir] | ||
* @param {TextlintKernelRule[]} rules rules and config set | ||
@@ -46,2 +47,3 @@ * @param {TextlintKernelFilterRule[]} filterRules rules filter rules and config set | ||
var config = _ref.config, | ||
configBaseDir = _ref.configBaseDir, | ||
rules = _ref.rules, | ||
@@ -56,2 +58,3 @@ filterRules = _ref.filterRules, | ||
_this.config = config; | ||
_this.configBaseDir = configBaseDir; | ||
_this.rules = rules; | ||
@@ -94,3 +97,4 @@ _this.filterRules = filterRules; | ||
ignoreReport: ignoreReport, | ||
textLintConfig: textLintConfig | ||
textLintConfig: textLintConfig, | ||
configBaseDir: _this2.configBaseDir | ||
}); | ||
@@ -97,0 +101,0 @@ var ruleModule = (0, _ruleCreatorHelper.getLinter)(rule); |
@@ -43,2 +43,5 @@ export interface TextlintKernelPlugin { | ||
filterRules?: TextlintKernelFilterRule[]; | ||
// config base directory | ||
// It is a value of context.getConfigBaseDir. | ||
configBaseDir?: string; | ||
} | ||
@@ -45,0 +48,0 @@ |
@@ -203,3 +203,4 @@ // MIT © 2017 azu | ||
rules = options.rules, | ||
filterRules = options.filterRules; | ||
filterRules = options.filterRules, | ||
configBaseDir = options.configBaseDir; | ||
@@ -223,3 +224,4 @@ var _processor$processor = processor.processor(ext), | ||
filterRules: filterRules, | ||
sourceCode: sourceCode | ||
sourceCode: sourceCode, | ||
configBaseDir: configBaseDir | ||
}).catch(function (error) { | ||
@@ -250,3 +252,4 @@ error.message = addingAtFileNameToError(filePath, error.message); | ||
rules = options.rules, | ||
filterRules = options.filterRules; | ||
filterRules = options.filterRules, | ||
configBaseDir = options.configBaseDir; | ||
@@ -272,3 +275,4 @@ assert(processor, "processor is not found for " + ext); | ||
filterRules: filterRules, | ||
sourceCode: sourceCode | ||
sourceCode: sourceCode, | ||
configBaseDir: configBaseDir | ||
}).catch(function (error) { | ||
@@ -275,0 +279,0 @@ error.message = addingAtFileNameToError(filePath, error.message); |
@@ -40,2 +40,5 @@ { | ||
"properties": { | ||
"configBaseDir": { | ||
"type": "string" | ||
}, | ||
"ext": { | ||
@@ -42,0 +45,0 @@ "type": "string" |
@@ -13,3 +13,3 @@ { | ||
"name": "@textlint/kernel", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "textlint kernel is core logic by pure JavaScript.", | ||
@@ -46,3 +46,3 @@ "main": "lib/textlint-kernel.js", | ||
"shelljs": "^0.7.7", | ||
"textlint-plugin-markdown": "^2.0.3", | ||
"textlint-plugin-markdown": "^2.0.4", | ||
"typescript-json-schema": "^0.11.0" | ||
@@ -49,0 +49,0 @@ }, |
@@ -7,3 +7,5 @@ // LICENSE : MIT | ||
import SeverityLevel from "../shared/type/SeverityLevel"; | ||
import {getSeverity} from "../shared/rule-severity"; | ||
import { getSeverity } from "../shared/rule-severity"; | ||
// instance for rule context | ||
const ruleFixer = new RuleFixer(); | ||
/** | ||
@@ -14,3 +16,2 @@ * This callback is displayed as a global member. | ||
*/ | ||
/** | ||
@@ -23,7 +24,13 @@ * Rule context object is passed to each rule as `context` | ||
* @param {Object|boolean} ruleOptions | ||
* @param {string} [configBaseDir] | ||
* @constructor | ||
*/ | ||
export default function RuleContext({ruleId, sourceCode, report, textLintConfig, ruleOptions}) { | ||
Object.defineProperty(this, "id", {value: ruleId}); | ||
Object.defineProperty(this, "config", {value: textLintConfig}); | ||
export default function RuleContext({ ruleId, sourceCode, report, textLintConfig, ruleOptions, configBaseDir }) { | ||
Object.defineProperty(this, "id", { value: ruleId }); | ||
/** | ||
* Please use `getConfigBaseDir` insteadof it. | ||
* @see https://github.com/textlint/textlint/issues/294 | ||
* @deprecated | ||
*/ | ||
Object.defineProperty(this, "config", { value: textLintConfig }); | ||
const severity = getSeverity(ruleOptions); | ||
@@ -36,9 +43,9 @@ | ||
*/ | ||
this.report = function (node, ruleError) { | ||
this.report = function(node, ruleError) { | ||
assert(!(node instanceof RuleError), "should be `report(node, ruleError);`"); | ||
if (ruleError instanceof RuleError) { | ||
report({ruleId, node, severity, ruleError}); | ||
report({ ruleId, node, severity, ruleError }); | ||
} else { | ||
const level = ruleError.severity || SeverityLevel.error; | ||
report({ruleId, node, severity: level, ruleError}); | ||
report({ ruleId, node, severity: level, ruleError }); | ||
} | ||
@@ -61,3 +68,20 @@ }; | ||
this.getSource = sourceCode.getSource.bind(sourceCode); | ||
/** | ||
* get config base directory path | ||
* config base directory path often is the place of .textlintrc | ||
* | ||
* e.g.) /path/to/dir/.textlintrc | ||
* `getConfigBaseDir()` return `"/path/to/dir/"`. | ||
* | ||
* When using textlint as module, it is specified by `configBaseDir` | ||
* If not found the value, return undefined. | ||
* | ||
* You can use it for resolving relative path from config dir. | ||
* @returns {string|undefined} | ||
*/ | ||
this.getConfigBaseDir = () => { | ||
return configBaseDir; | ||
}; | ||
/** | ||
* CustomError object | ||
@@ -71,3 +95,3 @@ * @type {RuleError} | ||
*/ | ||
this.fixer = new RuleFixer(); | ||
this.fixer = ruleFixer; | ||
} |
@@ -24,2 +24,3 @@ // LICENSE : MIT | ||
* @param {Config} config | ||
* @param {string} [configBaseDir] | ||
* @param {TextlintKernelRule[]} [rules] | ||
@@ -30,3 +31,3 @@ * @param {TextlintKernelFilterRule[]} [filterRules] | ||
*/ | ||
process({ config, rules = [], filterRules = [], sourceCode }) { | ||
process({ config, configBaseDir, rules = [], filterRules = [], sourceCode }) { | ||
assert(config && Array.isArray(rules) && Array.isArray(filterRules) && sourceCode); | ||
@@ -61,3 +62,4 @@ const { preProcess, postProcess } = this.processor.processor(sourceCode.ext); | ||
filterRules, | ||
sourceCode: newSourceCode | ||
sourceCode: newSourceCode, | ||
configBaseDir | ||
}); | ||
@@ -64,0 +66,0 @@ |
@@ -20,2 +20,3 @@ // LICENSE : MIT | ||
* @param {Config} config | ||
* @param {string} [configBaseDir | ||
* @param {TextlintKernelRule[]} [rules] | ||
@@ -26,3 +27,3 @@ * @param {TextlintKernelFilterRule[]} [filterRules] | ||
*/ | ||
process({ config, rules = [], filterRules = [], sourceCode }) { | ||
process({ config, configBaseDir, rules = [], filterRules = [], sourceCode }) { | ||
assert(config && Array.isArray(rules) && Array.isArray(filterRules) && sourceCode); | ||
@@ -36,3 +37,4 @@ const { preProcess, postProcess } = this.processor.processor(sourceCode.ext); | ||
filterRules, | ||
sourceCode | ||
sourceCode, | ||
configBaseDir | ||
}); | ||
@@ -39,0 +41,0 @@ return TaskRunner.process(task).then(messages => { |
@@ -12,2 +12,3 @@ // LICENSE : MIT | ||
* @param {Config} config | ||
* @param {string} [configBaseDir] | ||
* @param {TextlintKernelRule} fixerRule rules has fixer | ||
@@ -17,5 +18,6 @@ * @param {TextlintKernelFilterRule[]} filterRules filter rules and config set | ||
*/ | ||
constructor({ config, fixerRule, filterRules, sourceCode }) { | ||
constructor({ config, configBaseDir, fixerRule, filterRules, sourceCode }) { | ||
super(); | ||
this.config = config; | ||
this.configBaseDir = configBaseDir; | ||
this.fixerRule = fixerRule; | ||
@@ -45,3 +47,4 @@ this.filterRules = filterRules; | ||
ignoreReport, | ||
textLintConfig | ||
textLintConfig, | ||
configBaseDir: this.configBaseDir | ||
}); | ||
@@ -48,0 +51,0 @@ const ruleModule = getFixer(this.fixerRule.rule); |
@@ -12,2 +12,3 @@ // LICENSE : MIT | ||
* @param {Config} config | ||
* @param {string} [configBaseDir] | ||
* @param {TextlintKernelRule[]} rules rules and config set | ||
@@ -17,5 +18,6 @@ * @param {TextlintKernelFilterRule[]} filterRules rules filter rules and config set | ||
*/ | ||
constructor({ config, rules, filterRules, sourceCode }) { | ||
constructor({ config, configBaseDir, rules, filterRules, sourceCode }) { | ||
super(); | ||
this.config = config; | ||
this.configBaseDir = configBaseDir; | ||
this.rules = rules; | ||
@@ -48,3 +50,4 @@ this.filterRules = filterRules; | ||
ignoreReport, | ||
textLintConfig | ||
textLintConfig, | ||
configBaseDir: this.configBaseDir | ||
}); | ||
@@ -51,0 +54,0 @@ const ruleModule = getLinter(rule); |
@@ -43,2 +43,5 @@ export interface TextlintKernelPlugin { | ||
filterRules?: TextlintKernelFilterRule[]; | ||
// config base directory | ||
// It is a value of context.getConfigBaseDir. | ||
configBaseDir?: string; | ||
} | ||
@@ -45,0 +48,0 @@ |
@@ -152,3 +152,3 @@ // MIT © 2017 azu | ||
}) { | ||
const { ext, filePath, rules, filterRules } = options; | ||
const { ext, filePath, rules, filterRules, configBaseDir } = options; | ||
const { preProcess, postProcess } = processor.processor(ext); | ||
@@ -169,3 +169,4 @@ assert(typeof preProcess === "function" && typeof postProcess === "function", | ||
filterRules, | ||
sourceCode | ||
sourceCode, | ||
configBaseDir | ||
}).catch(error => { | ||
@@ -187,3 +188,3 @@ error.message = addingAtFileNameToError(filePath, error.message); | ||
_sequenceProcess({ processor, text, options }) { | ||
const { ext, filePath, rules, filterRules } = options; | ||
const { ext, filePath, rules, filterRules, configBaseDir } = options; | ||
assert(processor, `processor is not found for ${ext}`); | ||
@@ -205,3 +206,4 @@ const { preProcess, postProcess } = processor.processor(ext); | ||
filterRules, | ||
sourceCode | ||
sourceCode, | ||
configBaseDir | ||
}).catch(error => { | ||
@@ -208,0 +210,0 @@ error.message = addingAtFileNameToError(filePath, error.message); |
@@ -40,2 +40,5 @@ { | ||
"properties": { | ||
"configBaseDir": { | ||
"type": "string" | ||
}, | ||
"ext": { | ||
@@ -42,0 +45,0 @@ "type": "string" |
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
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
296864
98120
4585