From 2dce5a3d066a41d8af528ca504337f874c534113 Mon Sep 17 00:00:00 2001 From: Don Schrimsher Date: Wed, 3 Feb 2021 15:45:55 -0500 Subject: [PATCH 1/2] Add file to test fatal error handling logic Adds a file to the fixture git repo to 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. --- .gitignore | 1 + README.md | 14 ++++++++++++++ spec/fixtures/test.git/fatal-errors.js | 7 +++++++ spec/fixtures/test.git/git/index | Bin 209 -> 289 bytes spec/fixtures/test.git/git/logs/HEAD | 1 + .../fixtures/test.git/git/logs/refs/heads/curly | 1 + .../43/5e620e0e184d0db211cb66560ce92dec2e19ef | 2 ++ .../56/bd82c159eac355a205dea6be7e1016b6283fb9 | Bin 0 -> 104 bytes .../61/fc0828e28a1dd51d603769c0708028a4859079 | 1 + .../e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 | Bin 0 -> 15 bytes spec/fixtures/test.git/git/refs/heads/curly | 2 +- spec/spec_helper.rb | 2 ++ 12 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 spec/fixtures/test.git/fatal-errors.js create mode 100644 spec/fixtures/test.git/git/objects/43/5e620e0e184d0db211cb66560ce92dec2e19ef create mode 100644 spec/fixtures/test.git/git/objects/56/bd82c159eac355a205dea6be7e1016b6283fb9 create mode 100644 spec/fixtures/test.git/git/objects/61/fc0828e28a1dd51d603769c0708028a4859079 create mode 100644 spec/fixtures/test.git/git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 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/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 0b50aa9dba5e1558b06b0be6111dfb76abf9adc6..6df8a172d2ef128774723fd4884a0736c3f1c9de 100644 GIT binary patch delta 211 zcmcb}xR9yd#WTp6fq{Vuh?x_lxsDpHlrn@zSLY+mGf zRV4E!mP<|a>F;+0(3ftRsF!I&m&_%5GmhGz(5Zk6 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 0000000000000000000000000000000000000000..5b6863779c1c123932a06a4ceee13387f90b0d97 GIT binary patch literal 104 zcmV-u0GI!G0V^p=O;s>7G-EI{FfcPQQAkTHNzBnrEh@?{D%Q&?W=QLOD#6T Kst5q=>@Vtwmn~la literal 0 HcmV?d00001 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& Date: Fri, 5 Feb 2021 08:07:12 -0500 Subject: [PATCH 2/2] WIP: Fix bug causing line numbers to be swallowed Fixes a bug causing line numbers to be swallowed for fatal errors in ESLint. WIP since some tests are failing and they're a bit difficult to understand, so I haven't been able to figure out what's going on in a reasonable amount of time. Opening a WIP PR and issue to ask the author. --- lib/pronto/eslint.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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'] }