Skip to content
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

WIP: Fix bug causing line numbers to be swallowed #23

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ pkg/*
.bundle
.DS_Store
Gemfile.lock
spec/fixtures/test.git/git/COMMIT_EDITMSG
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
11 changes: 8 additions & 3 deletions lib/pronto/eslint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'] }
Expand Down
7 changes: 7 additions & 0 deletions spec/fixtures/test.git/fatal-errors.js
Original file line number Diff line number Diff line change
@@ -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 {}
Binary file modified spec/fixtures/test.git/git/index
Binary file not shown.
1 change: 1 addition & 0 deletions spec/fixtures/test.git/git/logs/HEAD
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ e438134aac40ce86789d552f1bdada6582a987f6 85e04b1eb1a721d42db51d49e49dfeb8255a574
931004157205727e6a47586feaed0473c6ddbd66 931004157205727e6a47586feaed0473c6ddbd66 Mindaugas Mozūras <[email protected]> 1456674177 +0200 checkout: moving from master to curly
931004157205727e6a47586feaed0473c6ddbd66 3a6237c5feacca9a37c36bec5110a1eeb9da703b Mindaugas Mozūras <[email protected]> 1456674189 +0200 commit: Add a line of code that does not have the correct curlies (eslint)
3a6237c5feacca9a37c36bec5110a1eeb9da703b 37018e429ad00f0ec961bd218e3dfa6a6e8cc05b Markus Doits <[email protected]> 1460316876 +0200 commit: add es6 file
37018e429ad00f0ec961bd218e3dfa6a6e8cc05b 435e620e0e184d0db211cb66560ce92dec2e19ef Don Schrimsher <[email protected]> 1612384977 -0500 commit: Add a file to test fatal error handling logic
1 change: 1 addition & 0 deletions spec/fixtures/test.git/git/logs/refs/heads/curly
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
0000000000000000000000000000000000000000 931004157205727e6a47586feaed0473c6ddbd66 Mindaugas Mozūras <[email protected]> 1456674177 +0200 branch: Created from HEAD
931004157205727e6a47586feaed0473c6ddbd66 3a6237c5feacca9a37c36bec5110a1eeb9da703b Mindaugas Mozūras <[email protected]> 1456674189 +0200 commit: Add a line of code that does not have the correct curlies (eslint)
3a6237c5feacca9a37c36bec5110a1eeb9da703b 37018e429ad00f0ec961bd218e3dfa6a6e8cc05b Markus Doits <[email protected]> 1460316876 +0200 commit: add es6 file
37018e429ad00f0ec961bd218e3dfa6a6e8cc05b 435e620e0e184d0db211cb66560ce92dec2e19ef Don Schrimsher <[email protected]> 1612384977 -0500 commit: Add a file to test fatal error handling logic
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
x��An� E��)f�U"l�ؖ����]w��0T,7��;I���@���1&-K`8��g"��d����Hhڮ�Fu�PO�S�j=�fh�4V+f� m��͈V)�Ȍ��l#g�u�Q�`��
7�)�[�p4>��x��dS| �锱pF�\�!=C��c��NuJU�&���7�z�\� 8Sap�8�,n��C<��N�Tէ垖u+d[��'����V � n�DYzr�^ Dx?~�_ae3���S�+�.�-��D P4i��dyU�D�[�A���p���� .\�<2�D%>���5e����B��
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
x%�AN�@ P�9��!U�J��ص�L<����Fqw�taya�}�MG���=8W6n���W8��+��3�vXՕ��B��:R���䩁z�nȂ���� ��dX+��}�Ϫ}Bn�lK$ɺ�S��$Q��*��l�̅��jrLJ&��<k��F���a��'��G�%˝g���~���GV�
Binary file not shown.
2 changes: 1 addition & 1 deletion spec/fixtures/test.git/git/refs/heads/curly
Original file line number Diff line number Diff line change
@@ -1 +1 @@
37018e429ad00f0ec961bd218e3dfa6a6e8cc05b
435e620e0e184d0db211cb66560ce92dec2e19ef
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@
RSpec.configure do |config|
config.expect_with(:rspec) { |c| c.syntax = :should }
config.mock_with(:rspec) { |c| c.syntax = :should }
config.filter_run focus: true
config.run_all_when_everything_filtered = true
end