Skip to content

Commit

Permalink
Merge pull request #30 from gucong3000/eclint_i18n
Browse files Browse the repository at this point in the history
eclint i18n
  • Loading branch information
gucong3000 authored Mar 29, 2017
2 parents ba1c7a2 + 919e500 commit c14f2c5
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 14 deletions.
1 change: 0 additions & 1 deletion lib/csslint-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class CssLintError extends LintError {

// 报错插件
plugin: 'CssLint',
name: 'CssLint',

// 文档
doc: rule.url,
Expand Down
1 change: 0 additions & 1 deletion lib/editorconfig-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class EditorConfigError extends LintError {

// 报错插件
plugin: 'EditorConfig',
name: 'EditorConfig',

// 文档
doc: error.rule && `https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties#${ error.rule }`
Expand Down
37 changes: 37 additions & 0 deletions lib/editorconfig_zh_CN.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'use strict';

const messages = new Map([
[/^invalid charset: (.+?), expected: (.+?)$/, '错误的文件编码:$1,期望:$2'],
[/^expected charset: (.+?)$/, '期望的文件编码:$1'],
[/^character out of latin1 range: (.+?)$/, '超出latin1编码范围的字符:$1'],

[/^invalid newline: (.+?), expected: (.+?)$/, '错误的缩进尺寸:$1,期望:$2'],

[/^invalid indent size: (\d+), expected: (\d+)$/, '错误的缩进尺寸:$1,期望:$2'],

['invalid indent style: found a leading space, expected: tab', '错误的缩进风格:使用了空格,期望:tab'],
['invalid indent style: found a leading tab, expected: space', '错误的缩进风格:使用了tab,期望:空格'],
[/^invalid indent style: found (\d+) soft tab\(s\)$/, '错误的缩进风格:发现$1个软缩进'],
[/^invalid indent style: found (\d+) hard tab\(s\)$/, '错误的缩进风格:发现$1个硬缩进'],

['expected final newline', '期望结尾换行'],
['unexpected final newline', '不许结尾换行'],

[/^invalid line length: (\d+), expected: (\d+)$/, '错误的行长度:$1,期望:$2以内'],

['trailing whitespace found', '行尾禁用空白'],
]);
module.exports = function(error) {
for (const [en, cn] of messages) {
if (en instanceof RegExp) {
if (en.test(error.message)) {
error.message = cn.replace(/\$\d+/, key => en[key]);
return error;
}
} else if (error.message === en) {
error.message = cn;
return error;
}
}
return error;
};
1 change: 0 additions & 1 deletion lib/eslint-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class ESLintError extends LintError {

// 报错插件
plugin: 'ESLint',
name: 'ESLint',

// 文档
doc: error.ruleId && `http://${ locale === 'zh_CN' ? 'cn.' : '' }eslint.org/docs/rules/${ error.ruleId }`
Expand Down
1 change: 0 additions & 1 deletion lib/jscs-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class JSCSError extends LintError {

// 报错插件
plugin: 'JSCS',
name: 'JSCS',

// 文档
doc: error.rule && `http://jscs.info/rule/${ error.rule }`
Expand Down
1 change: 0 additions & 1 deletion lib/jshint-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class JSHintError extends LintError {

// 报错插件
plugin: 'JSHint',
name: 'JSHint',

}, error);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/lint-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function i18n(error) {
if (locale === 'en_US') {
return error;
}
const key = error.name.toLowerCase();
const key = error.plugin.toLowerCase();
if (!(key in I18N_CACHE)) {
try {
I18N_CACHE[key] = require(`./${ key }_${ locale }`);
Expand Down
1 change: 0 additions & 1 deletion lib/postcss-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class PostCSSError extends LintError {

// 报错插件
plugin: 'PostCSS',
name: 'PostCSS',
doc: error.rule && error.plugin === 'stylelint' && `https://stylelint.io/user-guide/rules/${ error.rule }/`
}, error, {
// 错误等级
Expand Down
1 change: 0 additions & 1 deletion lib/tslint-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class TSLintError extends LintError {

// 报错插件
plugin: 'TSLint',
name: 'TSLint',

// 文档
doc: error.ruleName && `https://palantir.github.io/tslint/rules/${ error.ruleName }/`
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,5 @@
"pretest": "node-version-gte-4 && eslint lib test/*.test.js || echo \"ESLint not supported\"",
"test": "istanbul cover node_modules/mocha/bin/_mocha test/*.test.js"
},
"version": "1.7.0"
"version": "1.8.0"
}
7 changes: 2 additions & 5 deletions test/eclint.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@ describe('ECLint', function() {
assert.equal(ex.plugin, 'gulp-reporter');
assert.equal(ex.message, 'Lint failed for: test/fixtures/eclint/invalid.js');

assert.ok(gutil.log.lastCall.args[0].indexOf('invalid charset: utf-8-bom, expected: utf-8 (EditorConfig charset') >= 0);
assert.ok(gutil.log.lastCall.args[0].indexOf('https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties#charset)') >= 0);

assert.ok(gutil.log.lastCall.args[0].indexOf('invalid indentation: found a leading space, expected: tab') >= 0);
assert.ok(gutil.log.lastCall.args[0].indexOf('EditorConfig indent_style https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties#indent_style') >= 0);
assert.ok(gutil.log.lastCall.args[0].indexOf('(EditorConfig charset https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties#charset)') >= 0);
assert.ok(gutil.log.lastCall.args[0].indexOf('(EditorConfig indent_style https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties#indent_style') >= 0);

done();
});
Expand Down

0 comments on commit c14f2c5

Please sign in to comment.