diff --git a/lib/eclint.spec.ts b/lib/eclint.spec.ts index 60b2c7d..f5df261 100644 --- a/lib/eclint.spec.ts +++ b/lib/eclint.spec.ts @@ -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(); @@ -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, diff --git a/lib/eclint.ts b/lib/eclint.ts index fdff33d..381d553 100644 --- a/lib/eclint.ts +++ b/lib/eclint.ts @@ -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) { @@ -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) { @@ -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) => { diff --git a/package.json b/package.json index 6b4f891..da5f612 100644 --- a/package.json +++ b/package.json @@ -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",