node-lintspaces icon indicating copy to clipboard operation
node-lintspaces copied to clipboard

[EditorConfig] "insert_final_newline = false" doesn't produce warnings in files that contain final newlines.

Open EricDunsworth opened this issue 5 years ago • 1 comments

According to the EditorConfig website's supported properties section and https://github.com/editorconfig/editorconfig/issues/269#issuecomment-245500665, insert_final_newline = false is supposed to ensure a file doesn't end with a final newline. The EditorConfig editor plugins I tried also work in that way - they strip out final newlines when saving files associated to .editorconfig files that have that property set to false.

However, lintspaces' equivalent newline property doesn't work in the same way. According to the newline option's documentation, it's solely designed to check for the the presence of final newlines and isn't capable of doing the opposite.

Since lintspaces' .editorconfig option works by remapping insert_final_newline to newline, that causes a clash between both interpretations.

Could something be done to make lintspaces' .editorconfig option follow that format's more aggressive interpretation of insert_final_newline = false?

Code/Output samples... The samples below demonstrate how lintspaces currently reacts to insert_final_newline = false when a file contains a final newline.

.editorconfig

root = true

[*]
insert_final_newline = false

test.txt (contains a final newline)

test

check.js

var Validator = require('lintspaces');

var validator = new Validator({editorconfig: '.editorconfig'});
validator.validate('test.txt');

var results = validator.getInvalidFiles();

//Derived from https://stackoverflow.com/a/10729284
const util = require('util');

console.log(util.inspect(results, {showHidden: false, depth: null}));

Output when running node check.js in Windows:

{}

Expected output of node check.js:

{ 'test.txt':
   { '2':
      [ ValidationError {
          line: 2,
          code: 'NEWLINE_AMOUNT',
          type: 'warning',
          message: 'Unexpected additional newlines at the end of the file.' } ]
} }

EricDunsworth avatar Sep 17 '18 18:09 EricDunsworth

Hi @EricDunsworth, thank you for this detailed issue. You're totally right that lintspaces should react differently when getting the setting for newlines from .editorconfig (according the expected behaviour) or from the regular config/rcconfig. I think we need to extend the configuration to allow different kinds of error reportings depending on the origin of settings. As you can see settings from the editorconfig are more relevant than other ones which allows us to overwrite the default on/off-behaviours. I will fix this problem in a future release. However, if you need a faster fix, I would be very happy to accept a PR to solve this.

schorfES avatar Sep 24 '18 12:09 schorfES