From 62f69934f2508a25df988157925667d5efd8549e Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Tue, 6 Feb 2018 16:43:35 +0100 Subject: [PATCH 1/8] possible solution for [/] problem --- lib/coderay/scanners/java_script.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/coderay/scanners/java_script.rb b/lib/coderay/scanners/java_script.rb index 5e278137..6359c3f0 100644 --- a/lib/coderay/scanners/java_script.rb +++ b/lib/coderay/scanners/java_script.rb @@ -45,7 +45,7 @@ class JavaScript < Scanner STRING_CONTENT_PATTERN = { "'" => /[^\\']+/, '"' => /[^\\"]+/, - '/' => /[^\\\/]+/, + '/' => / (?: [^\\\/\[]+ | \[ ([^\]\\]+ | \\.)* \]? )+ /mx, } # :nodoc: KEY_CHECK_PATTERN = { "'" => / (?> [^\\']* (?: \\. [^\\']* )* ) ' \s* : /mx, From a351d9e26effb35e056fc6b7e9df4eb7e4ad306a Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Sun, 24 Nov 2019 01:44:53 +0100 Subject: [PATCH 2/8] use %r --- lib/coderay/scanners/java_script.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/coderay/scanners/java_script.rb b/lib/coderay/scanners/java_script.rb index 6359c3f0..e8872cac 100644 --- a/lib/coderay/scanners/java_script.rb +++ b/lib/coderay/scanners/java_script.rb @@ -45,7 +45,7 @@ class JavaScript < Scanner STRING_CONTENT_PATTERN = { "'" => /[^\\']+/, '"' => /[^\\"]+/, - '/' => / (?: [^\\\/\[]+ | \[ ([^\]\\]+ | \\.)* \]? )+ /mx, + '/' => %r{ (?: [^\\/\[]+ | \[ ([^\]\\]+ | \\.)* \]? )+ }mx, } # :nodoc: KEY_CHECK_PATTERN = { "'" => / (?> [^\\']* (?: \\. [^\\']* )* ) ' \s* : /mx, From 4c97c9165342f9c2aca99fd56cb49f8412610a0c Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Sun, 24 Nov 2019 01:55:07 +0100 Subject: [PATCH 3/8] whitespace --- lib/coderay/scanners/java_script.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/coderay/scanners/java_script.rb b/lib/coderay/scanners/java_script.rb index e8872cac..476afd9c 100644 --- a/lib/coderay/scanners/java_script.rb +++ b/lib/coderay/scanners/java_script.rb @@ -40,8 +40,8 @@ class JavaScript < Scanner add(KEYWORDS, :keyword) # :nodoc: ESCAPE = / [bfnrtv\n\\'"] | x[a-fA-F0-9]{1,2} | [0-7]{1,3} /x # :nodoc: - UNICODE_ESCAPE = / u[a-fA-F0-9]{4} | U[a-fA-F0-9]{8} /x # :nodoc: - REGEXP_ESCAPE = / [bBdDsSwW] /x # :nodoc: + UNICODE_ESCAPE = / u[a-fA-F0-9]{4} | U[a-fA-F0-9]{8} /x # :nodoc: + REGEXP_ESCAPE = / [bBdDsSwW] /x # :nodoc: STRING_CONTENT_PATTERN = { "'" => /[^\\']+/, '"' => /[^\\"]+/, From 5233abf74f43a4b36383c2ce00a5e6c0d67e6503 Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Sun, 24 Nov 2019 02:01:24 +0100 Subject: [PATCH 4/8] remove duplicated protected --- lib/coderay/scanners/java_script.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/coderay/scanners/java_script.rb b/lib/coderay/scanners/java_script.rb index 476afd9c..87686acf 100644 --- a/lib/coderay/scanners/java_script.rb +++ b/lib/coderay/scanners/java_script.rb @@ -219,8 +219,6 @@ def scan_tokens encoder, options encoder end - protected - def reset_instance super @xml_scanner.reset if defined? @xml_scanner From 37a21e2314d464dc7c1d2eb3a4542ae8ab984d3f Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Sun, 24 Nov 2019 02:12:27 +0100 Subject: [PATCH 5/8] provoke RubyCop --- lib/coderay/scanners/java_script.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/coderay/scanners/java_script.rb b/lib/coderay/scanners/java_script.rb index 87686acf..bb0d35be 100644 --- a/lib/coderay/scanners/java_script.rb +++ b/lib/coderay/scanners/java_script.rb @@ -42,7 +42,7 @@ class JavaScript < Scanner ESCAPE = / [bfnrtv\n\\'"] | x[a-fA-F0-9]{1,2} | [0-7]{1,3} /x # :nodoc: UNICODE_ESCAPE = / u[a-fA-F0-9]{4} | U[a-fA-F0-9]{8} /x # :nodoc: REGEXP_ESCAPE = / [bBdDsSwW] /x # :nodoc: - STRING_CONTENT_PATTERN = { + STRING_CONTENT_PATTERN = { "'" => /[^\\']+/, '"' => /[^\\"]+/, '/' => %r{ (?: [^\\/\[]+ | \[ ([^\]\\]+ | \\.)* \]? )+ }mx, From 261e1a8a400be5dee0e4cd2ac4c5d0c36fcab299 Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Sun, 24 Nov 2019 02:19:24 +0100 Subject: [PATCH 6/8] freeze Hash --- lib/coderay/scanners/java_script.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/coderay/scanners/java_script.rb b/lib/coderay/scanners/java_script.rb index bb0d35be..03913c0a 100644 --- a/lib/coderay/scanners/java_script.rb +++ b/lib/coderay/scanners/java_script.rb @@ -46,7 +46,7 @@ class JavaScript < Scanner "'" => /[^\\']+/, '"' => /[^\\"]+/, '/' => %r{ (?: [^\\/\[]+ | \[ ([^\]\\]+ | \\.)* \]? )+ }mx, - } # :nodoc: + }.freeze # :nodoc: KEY_CHECK_PATTERN = { "'" => / (?> [^\\']* (?: \\. [^\\']* )* ) ' \s* : /mx, '"' => / (?> [^\\"]* (?: \\. [^\\"]* )* ) " \s* : /mx, From c550eead73c80c7c1cbec7ccdb095aa4fd5fbf3f Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Sun, 24 Nov 2019 14:50:20 +0100 Subject: [PATCH 7/8] enfore SpaceAroundOperators --- .rubocop_todo.yml | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 57b00e4d..317e6a47 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -237,18 +237,7 @@ Layout/SpaceAfterComma: # Cop supports --auto-correct. # Configuration parameters: AllowForAlignment. Layout/SpaceAroundOperators: - Exclude: - - 'ideosyncratic-ruby.rb' - - 'lib/coderay/scanners/c.rb' - - 'lib/coderay/scanners/cpp.rb' - - 'lib/coderay/scanners/diff.rb' - - 'lib/coderay/scanners/groovy.rb' - - 'lib/coderay/scanners/java.rb' - - 'lib/coderay/scanners/java_script.rb' - - 'lib/coderay/scanners/python.rb' - - 'lib/coderay/scanners/ruby/patterns.rb' - - 'rake_tasks/code_statistics.rb' - - 'test/unit/json_encoder.rb' + AllowForAlignment: true # Offense count: 2 # Cop supports --auto-correct. From 26a682c45108782ed698d6743a2b41b3d9ac8942 Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Sun, 24 Nov 2019 14:55:02 +0100 Subject: [PATCH 8/8] tweaks to RuboCop config --- .rubocop.yml | 1 + .rubocop_todo.yml | 23 ----------------------- 2 files changed, 1 insertion(+), 23 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 978ab2bd..e248a433 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,6 +2,7 @@ inherit_from: .rubocop_todo.yml AllCops: TargetRubyVersion: 2.3 + DisplayStyleGuide: true Exclude: - 'test/scanners/**/*' - 'bench/example.ruby' diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 317e6a47..17f16e57 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -530,29 +530,6 @@ Naming/VariableNumber: Exclude: - 'test/unit/tokens.rb' -# Offense count: 1 -Performance/Caller: - Exclude: - - 'lib/coderay/scanners/scanner.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Performance/Casecmp: - Exclude: - - 'rake_tasks/generator.rake' - -# Offense count: 1 -# Cop supports --auto-correct. -Performance/StringReplacement: - Exclude: - - 'lib/coderay/encoders/html.rb' - -# Offense count: 3 -Performance/UnfreezeString: - Exclude: - - 'lib/coderay/encoders/encoder.rb' - - 'lib/coderay/encoders/html.rb' - # Offense count: 1 # Cop supports --auto-correct. # Configuration parameters: AutoCorrect.