Skip to content

Commit ee9de40

Browse files
Use Prism parser by default (#1897)
Default to using Prism parser if available
1 parent b299ca0 commit ee9de40

File tree

10 files changed

+20
-24
lines changed

10 files changed

+20
-24
lines changed

.circleci/config.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,6 @@ jobs:
4040
<<: *default
4141
docker:
4242
- image: cimg/ruby:3.2
43-
test-with-prism:
44-
<<: *default
45-
steps:
46-
- checkout
47-
- run: bundle check || bundle install
48-
- run:
49-
command: |
50-
gem install prism
51-
TEST_PRISM=true bundle exec rake
5243
upload-coverage:
5344
<<: *default
5445
working_directory: ~/repo
@@ -65,7 +56,6 @@ workflows:
6556
- default
6657
- test-3-1
6758
- test-3-2
68-
- test-with-prism
6959
- upload-coverage:
7060
requires:
7161
- test-3-1

Gemfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@ unless ENV['BM_PACKAGE']
66
group :test do
77
gem 'rake'
88
gem 'minitest'
9-
gem 'prism'
109
end
1110
end

brakeman.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Gem::Specification.new do |s|
3030
s.files += Dir['bundle/ruby/*/gems/**/*'].reject do |path|
3131
# Skip unnecessary files in dependencies
3232
path =~ %r{^bundle/ruby/\d\.\d\.\d/gems/[^\/]+/(Rakefile|benchmark|bin|doc|example|man|site|spec|test)} or
33-
path =~ %r{/gems/(io-console|racc|strscan)/}
33+
path =~ %r{/gems/(io-console|prism|racc|strscan)/}
3434
end
3535

3636
# racc is not only a built-in gem, but also has native code which we cannot

build.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env ruby
22
require 'fileutils'
3-
bundle_exclude = %w[io-console racc strscan]
3+
bundle_exclude = %w[io-console prism racc strscan]
44

55
puts 'Packaging Brakeman gem...'
66

gem_common.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def self.extended_dependencies spec
2222
spec.add_dependency "haml", "~>5.1"
2323
spec.add_dependency "slim", ">=1.3.6", "< 5.3"
2424
spec.add_dependency "rexml", "~>3.0"
25+
spec.add_dependency "prism", "~>1.3"
2526
end
2627
end
2728
end

lib/brakeman.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,15 @@ def self.run options
8484
options[:report_progress] = false
8585
end
8686

87+
if options[:use_prism]
88+
begin
89+
require 'prism'
90+
notify '[Notice] Using Prism parser'
91+
rescue LoadError => e
92+
Brakeman.debug "[Notice] Asked to use Prism, but failed to load: #{e}"
93+
end
94+
end
95+
8796
scan options
8897
end
8998

@@ -196,6 +205,7 @@ def self.default_options
196205
:pager => true,
197206
:parallel_checks => true,
198207
:parser_timeout => 10,
208+
:use_prism => true,
199209
:relative_path => false,
200210
:report_progress => true,
201211
:safe_methods => Set.new,

lib/brakeman/file_parser.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ def initialize app_tree, timeout, parallel = true, use_prism = false
1313
if @use_prism
1414
begin
1515
require 'prism'
16+
Brakeman.debug '[Notice] Using Prism parser'
1617
rescue LoadError => e
17-
Brakeman.debug "Asked to use Prism, but failed to load: #{e}"
18+
Brakeman.debug "[Notice] Asked to use Prism, but failed to load: #{e}"
1819
@use_prism = false
1920
end
2021
end

lib/brakeman/options.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,13 @@ def create_option_parser options
161161

162162
opts.on "--[no-]prism", "Use the Prism parser" do |use_prism|
163163
if use_prism
164-
prism_version = '1.0'
164+
min_prism_version = '1.3.0'
165165

166166
begin
167-
# Specifying minimum version here,
168-
# since it can't be in the gem dependency list because it is optional
169-
gem 'prism', ">=#{prism_version}"
167+
gem 'prism', ">=#{min_prism_version}"
168+
require 'prism'
170169
rescue Gem::MissingSpecVersionError, Gem::MissingSpecError, Gem::LoadError => e
171-
$stderr.puts "Please install `prism` version #{prism_version} or newer:"
170+
$stderr.puts "Please install `prism` version #{min_prism_version} or newer:"
172171
raise e
173172
end
174173
end

test/tests/rails52.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,6 @@ def test_sql_injection_foreign_key
104104
end
105105

106106
def test_sql_injection_user_input
107-
if ENV['TEST_PRISM']
108-
skip 'Un-skip as soon as Prism >1.2.0 is released'
109-
end
110-
111107
assert_warning :type => :warning,
112108
:warning_code => 0,
113109
:fingerprint => "f7affe2dfe9e3a48f39f1fb86224e150e60555a73f2e78fb499eadd298233625",

test/tests/rails8.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class Rails8Tests < Minitest::Test
77
def report
88
@@report ||=
99
Date.stub :today, Date.parse("2024-05-13") do
10-
BrakemanTester.run_scan "rails8", "Rails 8", run_all_checks: true, use_prism: true
10+
BrakemanTester.run_scan "rails8", "Rails 8", run_all_checks: true, use_prism: false
1111
end
1212
end
1313

0 commit comments

Comments
 (0)