New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
--fix mangles lines with trailing whitespace #6933
Comments
I cant reproduce this issue, here is what i did: test.js /* eslint "no-trailing-spaces": ["warn", {"skipBlankLines": true}] */
var _ = require('lodash');
function Controller($scope){
var ctrl = this;
function save(){
if ($scope.foo.bar.$dirty){
ctrl.foo.bars.forEach(function(bar,index) {
bar.dirty = $scope.foo.bar['first'+index].$dirty ||
$scope.foo.bar['add'+index].$dirty ||
$scope.foo.bar['replace'+index].$dirty;
});
}
}
} Run: GS025879@WIN1551863 MINGW64 ~/Documents/webstrom/test
$ ./node_modules/.bin/eslint -v
v3.3.1
GS025879@WIN1551863 MINGW64 ~/Documents/webstrom/test
$ ./node_modules/.bin/eslint test.js --no-eslintrc --color
C:\Users\gs025879\Documents\webstrom\test\test.js
11:68 warning Trailing spaces not allowed no-trailing-spaces
12:66 warning Trailing spaces not allowed no-trailing-spaces
✖ 2 problems (0 errors, 2 warnings)
GS025879@WIN1551863 MINGW64 ~/Documents/webstrom/test
$ ./node_modules/.bin/eslint test.js --no-eslintrc --color --fix
GS025879@WIN1551863 MINGW64 ~/Documents/webstrom/test
$
Final file: /* eslint "no-trailing-spaces": ["warn", {"skipBlankLines": true}] */
var _ = require('lodash');
function Controller($scope){
var ctrl = this;
function save(){
if ($scope.foo.bar.$dirty){
ctrl.foo.bars.forEach(function(bar,index) {
bar.dirty = $scope.foo.bar['first'+index].$dirty ||
$scope.foo.bar['add'+index].$dirty ||
$scope.foo.bar['replace'+index].$dirty;
});
}
}
} UPDATE: |
I've seen this sort of thing happen at my work, but I could never reliably reproduce it. Can you please reduce the test case? For example, if we're fairly sure that no-trailing-spaces is the rule which is linting/fixing and causing this problem, see what happens when your config only has |
When I turned that rule off, the problem was still happening so maybe it is not that rule. I was also not able to recreate the problem when I copied the source code from this bug listing and tried it again. Here is a ZIP of the exact file and .eslintrc that I am using. I was able to unzip this and recreate the problem. |
I could reproduce with the zip. |
If `skipBlankLines` option is enabled, counting total length for blank lines was lacking.
@mysticatea Just curious, what was the difference between the code in zip file vs the one on the issue? |
The one in the zip has four spaces on the line below |
ah, i see. Thanks @eviljoe for explaining. |
Yup. The different is 4 whitespaces in a blank line. var _ = require('lodash');
function Controller($scope){
var ctrl = this;
// ← THERE WERE 4 SPACES.
function save(){
if ($scope.foo.bar.$dirty){
ctrl.foo.bars.forEach(function(bar,index) {
bar.dirty = $scope.foo.bar['first'+index].$dirty || // ← When it removes this trailing space, it removed "r" at the 6 chars (4 spaces and \r\n) left side from the trailing space because the blank line was ignored.
$scope.foo.bar['add'+index].$dirty ||
$scope.foo.bar['replace'+index].$dirty;
});
}
}
} |
If `skipBlankLines` option is enabled, counting total length for blank lines was lacking.
If `skipBlankLines` option is enabled, counting total length for blank lines was lacking.
What version of ESLint are you using?
3.3.0
What parser (default, Babel-ESLint, etc.) are you using?
default
Please show your full configuration:
What did you do? Please include the actual source code causing the issue.
When attempting to use the
--fix
option on the file below, ESLint mangles the source file by incorrectly removing characters from lines with trailing whitespace.This is the command that I ran:
This is the original file. The lines that end with
.$dirty ||
have a single space at the end of the line.What did you expect to happen?
I ran this command on the file:
I expected ESLint to remove the whitespace character from the end of the line.
What actually happened? Please include the actual, raw output from ESLint.
This is the file after the command
eslint --fix test.js
is run:The lines that previously ended in
.$dirty ||
now end inty ||
. ESLint removed.dir
from those lines.This is the output from ESLint:
The text was updated successfully, but these errors were encountered: