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

Commit

Permalink
Support for value unset (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
gucong3000 authored Apr 14, 2018
1 parent 3b18975 commit d5fc37e
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 8 deletions.
49 changes: 49 additions & 0 deletions lib/eclint.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,31 @@ describe('eclint gulp plugin', () => {
}));
});

it('fix by "unset" options', (done) => {

const stream = eclint.fix({
settings: {
charset: 'unset',
end_of_line: 'unset',
indent_style: 'unset',
},
});

stream.on('data', (file: eclint.IEditorConfigLintFile) => {
expect(file.editorconfig).to.be.ok;
expect(file.editorconfig.fixed).to.be.ok;
expect(file.editorconfig.errors).to.have.lengthOf(0);
done();
});

stream.on('error', done);

stream.write(new File({
contents: new Buffer([0xef, 0xbb, 0xbf, 0x74, 0x65, 0x73, 0x74, 0x63, 0x61, 0x73, 0x65, 0x0a]),
path: path.join(__dirname, 'testcase.js'),
}));
});

it('checks after fix', (done) => {
const stream = eclint.fix();

Expand Down Expand Up @@ -148,6 +173,30 @@ describe('eclint gulp plugin', () => {

describe('check file', () => {

it('check by "unset" options', (done) => {

const stream = eclint.check({
settings: {
charset: 'unset',
end_of_line: 'unset',
indent_style: 'unset',
},
});

stream.on('data', (file: eclint.IEditorConfigLintFile) => {
expect(file.editorconfig).to.be.ok;
expect(file.editorconfig.errors).to.have.lengthOf(0);
done();
});

stream.on('error', done);

stream.write(new File({
contents: new Buffer([0xef, 0xbb, 0xbf, 0x74, 0x65, 0x73, 0x74, 0x63, 0x61, 0x73, 0x65, 0x0a]),
path: path.join(__dirname, 'testcase.js'),
}));
});

it('should skip null', (done) => {
vfs.src('lib', {
stripBOM: false,
Expand Down
20 changes: 13 additions & 7 deletions lib/eclint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,17 @@ _.without(
rules[name] = require('./rules/' + name);
});

function getSettings(fileSettings: ISettings, commandSettings: ISettings) {
return _.omit(
_.assign(fileSettings, commandSettings),
['tab_width'],
);
function getSettings(fileSettings: editorconfig.KnownProps, commandSettings: ISettings | editorconfig.KnownProps) {
return _.pickBy(
_.omit(
_.assign(
fileSettings,
commandSettings,
),
['tab_width'],
),
(value) => value !== 'unset',
) as ISettings;
}

function updateResult(file: IEditorConfigLintFile, options: any) {
Expand Down Expand Up @@ -178,7 +184,7 @@ export function check(options?: ICheckCommandOptions): stream.Transform {
.then((fileSettings: editorconfig.KnownProps) => {
const errors: EditorConfigError[] = [];

const settings = getSettings(fileSettings as ISettings, commandSettings);
const settings = getSettings(fileSettings, commandSettings);
const document = doc.create(file.contents, settings);

function addError(error?: EditorConfigError) {
Expand Down Expand Up @@ -249,7 +255,7 @@ export function fix(options?: ICommandOptions): stream.Transform {
);
}

const settings = getSettings(fileSettings as ISettings, commandSettings);
const settings = getSettings(fileSettings, commandSettings);
const document = doc.create(file.contents, settings);

Object.keys(settings).forEach((setting) => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eclint",
"version": "2.6.1",
"version": "2.7.0",
"description": "Validate or fix code that doesn't adhere to EditorConfig settings or infer settings from existing code.",
"keywords": [
"editorconfig",
Expand Down

0 comments on commit d5fc37e

Please sign in to comment.