Skip to content

Commit

Permalink
Simplify ESLint regexes
Browse files Browse the repository at this point in the history
The leading `.*` served no real purpose here, so we can just discard it.
Likewise, now that we are using ESLint only, we can simplify the regex
from checking for either double- or single-quotes to just check for
double quotes, since that is what ESLint uses.
  • Loading branch information
lencioni committed Dec 14, 2015
1 parent 4480dba commit de3c9ee
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions lib/import_js/importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def fix_imports
def import_all
@config.refresh
undefined_variables = run_eslint_command.map do |line|
/.*['"]([^'"]+)['"] is not defined/.match(line) do |match_data|
/"([^"]+)" is not defined/.match(line) do |match_data|
match_data[1]
end
end.compact.uniq
Expand All @@ -73,7 +73,7 @@ def import_all
def remove_unused_imports
@config.refresh
unused_variables = run_eslint_command.map do |line|
/.*['"]([^'"]+)['"] is defined but never used/.match(line) do |match_data|
/"([^"]+)" is defined but never used/.match(line) do |match_data|
match_data[1]
end
end.compact.uniq
Expand Down
26 changes: 13 additions & 13 deletions spec/import_js/importer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,7 @@ def self.current_selection=(index)
context 'when one undefined variable exists' do
let(:existing_files) { ['bar/foo.jsx'] }
let(:eslint_result) do
"stdin: line 3, col 11, 'foo' is not defined."
"stdin: line 3, col 11, \"foo\" is not defined."
end

it 'imports that variable' do
Expand All @@ -1122,7 +1122,7 @@ def self.current_selection=(index)
context 'when eslint returns other issues' do
let(:eslint_result) do
"stdin: line 1, col 1, Use the function form of \"use strict\".\n" \
"stdin: line 3, col 11, 'foo' is not defined."
"stdin: line 3, col 11, \"foo\" is not defined."
end

it 'still imports the variable' do
Expand Down Expand Up @@ -1154,8 +1154,8 @@ def self.current_selection=(index)
let(:text) { 'var a = foo + bar;' }

let(:eslint_result) do
"stdin: line 3, col 11, 'foo' is not defined.\n" \
"stdin: line 3, col 11, 'bar' is not defined."
"stdin: line 3, col 11, \"foo\" is not defined.\n" \
"stdin: line 3, col 11, \"bar\" is not defined."
end

it 'imports all variables' do
Expand All @@ -1173,10 +1173,10 @@ def self.current_selection=(index)
let(:text) { 'var a = foo + bar;' }

let(:eslint_result) do
"stdin: line 3, col 11, 'foo' is not defined.\n" +
"stdin: line 3, col 11, 'foo' is not defined.\n" +
"stdin: line 3, col 11, 'foo' is not defined.\n" +
"stdin: line 3, col 11, 'bar' is not defined."
"stdin: line 3, col 11, \"foo\" is not defined.\n" +
"stdin: line 3, col 11, \"foo\" is not defined.\n" +
"stdin: line 3, col 11, \"foo\" is not defined.\n" +
"stdin: line 3, col 11, \"bar\" is not defined."
end

it 'imports all variables' do
Expand Down Expand Up @@ -1227,7 +1227,7 @@ def self.current_selection=(index)
bar
EOS
let(:eslint_result) do
"stdin: line 1, col 4, 'foo' is defined but never used"
"stdin: line 1, col 4, \"foo\" is defined but never used"
end

it 'removes that import' do
Expand All @@ -1249,8 +1249,8 @@ def self.current_selection=(index)
EOS

let(:eslint_result) do
"stdin: line 3, col 11, 'foo' is defined but never used\n" \
"stdin: line 3, col 11, 'bar' is defined but never used"
"stdin: line 3, col 11, \"foo\" is defined but never used\n" \
"stdin: line 3, col 11, \"bar\" is defined but never used"
end

it 'removes all unused imports' do
Expand All @@ -1270,7 +1270,7 @@ def self.current_selection=(index)
EOS

let(:eslint_result) do
"stdin: line 3, col 11, 'foo' is defined but never used\n" \
"stdin: line 3, col 11, \"foo\" is defined but never used\n" \
end

it 'removes that variable from the destructured list' do
Expand All @@ -1291,7 +1291,7 @@ def self.current_selection=(index)
EOS

let(:eslint_result) do
"stdin: line 3, col 11, 'foo' is defined but never used\n" \
"stdin: line 3, col 11, \"foo\" is defined but never used\n" \
end

it 'removes the whole import' do
Expand Down

0 comments on commit de3c9ee

Please sign in to comment.