diff --git a/.gitignore b/.gitignore index 2ac8271..32b35f2 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ pkg/* .bundle .DS_Store Gemfile.lock +spec/fixtures/test.git/git/COMMIT_EDITMSG \ No newline at end of file diff --git a/README.md b/README.md index 9bf64cd..81bb81c 100644 --- a/README.md +++ b/README.md @@ -15,3 +15,17 @@ You'll need to install one of the runtimes supported by [ExecJS](https://github. Configuring ESLint via .eslintrc will work just fine with pronto-eslint, though it will not support searching higher up the path hierarch. To use an absolute path to your config, use `ESLINT_CONFIG`. + +## Testing + +The tests use a fixture git repository that has been created under the spec/fixtures/test.git folder. This folder is almost like a child repo of the parent repo where this README is contained. If you need to add or modify a test, you might need to modify the child repository. To do this, perform the following steps: + +1. Navigate to the `spec/fixtures/test.git` directory. +2. mv the `git` folder to `.git` to make the child git repo active again: `mv git .git`. +3. Add/modify/remove a file. +4. Add and commit all of the changes: `git commit -a`. +5. Move the `.git` folder back to the `git` folder so that the changes show up in the parent repo: `mv .git git`. +6. Navigate back to the root directory: `cd ../../../` +7. Add and commit all of the changes in the parent repo: `git commit -a`. + +If you run `git status` after moving the `.git` folder back to the `git` folder, you can see a list of the files that git has changed that will be committed in the parent repo. diff --git a/lib/pronto/eslint.rb b/lib/pronto/eslint.rb index dce22ae..9119af9 100644 --- a/lib/pronto/eslint.rb +++ b/lib/pronto/eslint.rb @@ -15,10 +15,15 @@ def run def inspect(patch) offences = Eslintrb.lint(patch.new_file_full_path, options).compact - fatals = offences.select { |offence| offence['fatal'] } - .map { |offence| new_message(offence, nil) } + fatals = offences.map do |offence| + fatal_offence = -> (line) { offence['fatal'] && (!offence['line'] || line.new_lineno == offence['line']) } + patch + .added_lines + .select(&fatal_offence) + .map { |line| new_message(offence, line) } + end - return fatals if fatals && !fatals.empty? + return fatals if fatals && !fatals.flatten.empty? offences.map do |offence| patch.added_lines.select { |line| line.new_lineno == offence['line'] } diff --git a/spec/fixtures/test.git/fatal-errors.js b/spec/fixtures/test.git/fatal-errors.js new file mode 100644 index 0000000..61fc082 --- /dev/null +++ b/spec/fixtures/test.git/fatal-errors.js @@ -0,0 +1,7 @@ +/* + * This file is used to test the logic for showing line numbers for fatal errors + * in ESLint - such as when the keyword class is encountered and a version of ES + * is specified that doesn't support classes. + */ + +class SomeJavascriptKlass {} diff --git a/spec/fixtures/test.git/git/index b/spec/fixtures/test.git/git/index index 0b50aa9..6df8a17 100644 Binary files a/spec/fixtures/test.git/git/index and b/spec/fixtures/test.git/git/index differ diff --git a/spec/fixtures/test.git/git/logs/HEAD b/spec/fixtures/test.git/git/logs/HEAD index a4f13f8..cca4bfa 100644 --- a/spec/fixtures/test.git/git/logs/HEAD +++ b/spec/fixtures/test.git/git/logs/HEAD @@ -12,3 +12,4 @@ e438134aac40ce86789d552f1bdada6582a987f6 85e04b1eb1a721d42db51d49e49dfeb8255a574 931004157205727e6a47586feaed0473c6ddbd66 931004157205727e6a47586feaed0473c6ddbd66 Mindaugas Mozūras 1456674177 +0200 checkout: moving from master to curly 931004157205727e6a47586feaed0473c6ddbd66 3a6237c5feacca9a37c36bec5110a1eeb9da703b Mindaugas Mozūras 1456674189 +0200 commit: Add a line of code that does not have the correct curlies (eslint) 3a6237c5feacca9a37c36bec5110a1eeb9da703b 37018e429ad00f0ec961bd218e3dfa6a6e8cc05b Markus Doits 1460316876 +0200 commit: add es6 file +37018e429ad00f0ec961bd218e3dfa6a6e8cc05b 435e620e0e184d0db211cb66560ce92dec2e19ef Don Schrimsher 1612384977 -0500 commit: Add a file to test fatal error handling logic diff --git a/spec/fixtures/test.git/git/logs/refs/heads/curly b/spec/fixtures/test.git/git/logs/refs/heads/curly index 11582e5..dda56df 100644 --- a/spec/fixtures/test.git/git/logs/refs/heads/curly +++ b/spec/fixtures/test.git/git/logs/refs/heads/curly @@ -1,3 +1,4 @@ 0000000000000000000000000000000000000000 931004157205727e6a47586feaed0473c6ddbd66 Mindaugas Mozūras 1456674177 +0200 branch: Created from HEAD 931004157205727e6a47586feaed0473c6ddbd66 3a6237c5feacca9a37c36bec5110a1eeb9da703b Mindaugas Mozūras 1456674189 +0200 commit: Add a line of code that does not have the correct curlies (eslint) 3a6237c5feacca9a37c36bec5110a1eeb9da703b 37018e429ad00f0ec961bd218e3dfa6a6e8cc05b Markus Doits 1460316876 +0200 commit: add es6 file +37018e429ad00f0ec961bd218e3dfa6a6e8cc05b 435e620e0e184d0db211cb66560ce92dec2e19ef Don Schrimsher 1612384977 -0500 commit: Add a file to test fatal error handling logic diff --git a/spec/fixtures/test.git/git/objects/43/5e620e0e184d0db211cb66560ce92dec2e19ef b/spec/fixtures/test.git/git/objects/43/5e620e0e184d0db211cb66560ce92dec2e19ef new file mode 100644 index 0000000..627b01a --- /dev/null +++ b/spec/fixtures/test.git/git/objects/43/5e620e0e184d0db211cb66560ce92dec2e19ef @@ -0,0 +1,2 @@ +xAn E)fU"lؖ]w0T,7;I@1&-K`8g"dHhڮFuPOSj=fh4V+f m͈V)Ȍl#guQ` +7)[p4>xdS| 锱pF\!=CcNuJU&7z\ 8Sap8,nC5eB \ No newline at end of file diff --git a/spec/fixtures/test.git/git/objects/56/bd82c159eac355a205dea6be7e1016b6283fb9 b/spec/fixtures/test.git/git/objects/56/bd82c159eac355a205dea6be7e1016b6283fb9 new file mode 100644 index 0000000..5b68637 Binary files /dev/null and b/spec/fixtures/test.git/git/objects/56/bd82c159eac355a205dea6be7e1016b6283fb9 differ diff --git a/spec/fixtures/test.git/git/objects/61/fc0828e28a1dd51d603769c0708028a4859079 b/spec/fixtures/test.git/git/objects/61/fc0828e28a1dd51d603769c0708028a4859079 new file mode 100644 index 0000000..b3bbb37 --- /dev/null +++ b/spec/fixtures/test.git/git/objects/61/fc0828e28a1dd51d603769c0708028a4859079 @@ -0,0 +1 @@ +x%AN@ P9!UJصL<Fqwtaya}MG=8W6nW8+3vXՕB:R䩁znȂ dX+}Ϫ}BnlK$ɺS$Q*l̅jrLJ&