Skip to content
This repository has been archived by the owner on Oct 4, 2020. It is now read-only.

remove y18n #109

Merged
merged 1 commit into from
Nov 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/cli.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ describe('eclint cli', function() {
'trim_trailing_whitespace': true,
'end_of_line': 'lf',
'insert_final_newline': true,
'max_line_length': 80
'max_line_length': 70
});
});
});
Expand Down
4 changes: 2 additions & 2 deletions lib/editor-config-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ class EditorConfigError extends Error {
` at (${ this.fileName }:${ this.lineNumber }:${ this.columnNumber })`
].join(os.EOL);
};
constructor(message: any[]) {
constructor(message: string, ...args) {
super();
this.message = i18n(...message);
this.message = i18n(message, ...args);
}
}

Expand Down
2 changes: 2 additions & 0 deletions lib/i18n.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ function i18n(lang) {
describe('eclint i18n', function() {
it('zh_CN', () => {
expect(i18n('zh_CN')('CommandError: Missing required sub-command.')).to.be.equal('命令错误: 缺少必须的子命令。');
const message = 'string that not exist in locales';
expect(i18n('zh_CN')(message)).to.be.equal(message);
});
it('ja_JP', () => {
const message = 'CommandError: Missing required sub-command.';
Expand Down
18 changes: 10 additions & 8 deletions lib/i18n.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import path = require('path');
import osLocale = require('os-locale');
import util = require('util');
let locale;
try {
locale = require(`../locales/${osLocale.sync()}.json`);
} catch (ex) {
locale = require('../locales/en.json');
}

const y18n = require('y18n')({
updateFiles: false,
directory: path.resolve(__dirname, '../locales'),
locale: osLocale.sync({ spawn: false })
});

export = y18n.__.bind(y18n);
export = (str: string, ...args) => {
return util.format(locale[str] || str, ...args);
};
10 changes: 5 additions & 5 deletions lib/rules/charset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ function resolve(settings: eclint.Settings) {
}

function check(settings: eclint.Settings, document: doc.Document) {
function creatErrorArray(message: any[]) {
var error = new EditorConfigError(message);
function creatErrorArray(message: string, ...args) {
var error = new EditorConfigError(message, ...args);
var source = '';
document.lines.some(function(line) {
if (/\S/.test(line.text)) {
Expand All @@ -36,7 +36,7 @@ function check(settings: eclint.Settings, document: doc.Document) {
var configSetting = resolve(settings);
if (inferredSetting) {
if (inferredSetting !== settings.charset) {
return creatErrorArray(['invalid charset: %s, expected: %s', inferredSetting, configSetting]);
return creatErrorArray('invalid charset: %s, expected: %s', inferredSetting, configSetting);
}
return [];
}
Expand All @@ -45,7 +45,7 @@ function check(settings: eclint.Settings, document: doc.Document) {
return [].concat.apply([], errors);
}
if (_.includes(Object.keys(boms), configSetting)) {
return creatErrorArray(['expected charset: %s', settings.charset]);
return creatErrorArray('expected charset: %s', settings.charset);
}
return [];
}
Expand All @@ -62,7 +62,7 @@ function infer(document: doc.Document): string {
function checkLatin1TextRange(line: doc.Line) {
return [].slice.call(line.text, 0).map(function(character: string, i: number) {
if (character.charCodeAt(0) >= 0x80) {
var error = new EditorConfigError(['character out of latin1 range: %s', JSON.stringify(character)]);
var error = new EditorConfigError('character out of latin1 range: %s', JSON.stringify(character));
error.lineNumber = line.number;
error.columnNumber = i + 1;
error.source = line.text;
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/end_of_line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ function check(settings: eclint.Settings, line: doc.Line) {
return;
}
if (inferredSetting !== configSetting) {
var error = new EditorConfigError([
var error = new EditorConfigError(
'invalid newline: %s, expected: %s',
inferredSetting,
configSetting
]);
);
error.lineNumber = line.number;
error.columnNumber = line.text.length + 1;
error.rule = 'end_of_line';
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/indent_size.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ function checkLine(line: doc.Line, indentSize: number): EditorConfigError {
var expectedIndentSize = softTabCount * indentSize;

if (line.prefix.length !== expectedIndentSize) {
var error = new EditorConfigError([
var error = new EditorConfigError(
'invalid indent size: %s, expected: %s',
line.prefix.length,
expectedIndentSize,
]);
);
error.lineNumber = line.number;
error.rule = 'indent_size';
error.source = line.text;
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/indent_style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function checkLine(line: doc.Line, indentStyle: IndentStyle) {
}

if (errorColumnNumber) {
var error = new EditorConfigError([errorMessage]);
var error = new EditorConfigError(errorMessage);
error.lineNumber = line.number;
error.columnNumber = errorColumnNumber;
error.rule = 'indent_style';
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/insert_final_newline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function check(settings: eclint.Settings, document: doc.Document) {
message = 'unexpected final newline';
}

var error = new EditorConfigError([message]);
var error = new EditorConfigError(message);
error.lineNumber = document.lines.length;
var lastLine: doc.Line = document.lines[document.lines.length - 1];
error.columnNumber = lastLine.text.length + lastLine.ending.length;
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/max_line_length.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ function check(settings: eclint.Settings, line: doc.Line) {
var inferredSetting = infer(line);
var configSetting = resolve(settings);
if (inferredSetting > settings.max_line_length) {
var error = new EditorConfigError([
var error = new EditorConfigError(
'invalid line length: %s, exceeds: %s',
inferredSetting,
configSetting
]);
);
error.lineNumber = line.number;
error.columnNumber = settings.max_line_length;
error.rule = 'max_line_length';
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/trim_trailing_whitespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function resolve(settings: eclint.Settings) {
function check(settings: eclint.Settings, line: doc.Line) {
var configSetting = resolve(settings);
if (configSetting && !infer(line)) {
var error = new EditorConfigError(['unexpected trailing whitespace']);
var error = new EditorConfigError('unexpected trailing whitespace');
error.lineNumber = line.number;
error.columnNumber = line.prefix.length + line.string.length + 1;
error.rule = 'trim_trailing_whitespace';
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
"through2": "^2.0.3",
"vinyl": "^2.1.0",
"vinyl-fs": "^2.4.4",
"y18n": "^3.2.1",
"yargs": "^10.0.3"
},
"devDependencies": {
Expand All @@ -83,7 +82,7 @@
"@types/get-stream": "^3.0.1",
"@types/lodash": "^4.14.82",
"@types/mocha": "^2.2.44",
"@types/node": "^8.0.47",
"@types/node": "^8.0.50",
"@types/proxyquire": "^1.3.28",
"@types/sinon": "^2.3.7",
"@types/sinon-chai": "^2.7.29",
Expand All @@ -99,7 +98,7 @@
"nyc": "^11.3.0",
"proxyquire": "^1.8.0",
"rimraf": "^2.6.2",
"sinon": "^4.1.1",
"sinon": "^4.1.2",
"sinon-chai": "^2.14.0",
"ts-node": "^3.3.0",
"tslint": "^5.8.0",
Expand Down