magic_frozen_string_literal 0.0.5 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.rdoc +5 -1
  3. data/lib/add_magic_comment.rb +11 -10
  4. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b6e04f9d975faac5b9bb731407d17810757891f2
4
- data.tar.gz: 58d338693c0a50d2d9b08d35ed00e5d6fead18dc
3
+ metadata.gz: 80af2fba8814ca3b424f9ce5e49db53f539a15a3
4
+ data.tar.gz: d38df55bdcb2879fbaf57d566d9cdb4c2f44d4ef
5
5
  SHA512:
6
- metadata.gz: 1f976e4559c85fd09341b00542bf6c8d2857a083c82da5b0e17444eed92e113cb2a74ab11b9268eb3d74bff20ee92e678a5bcc6be8abb3ffaefd2e2032deab96
7
- data.tar.gz: a4473211577a551684095cc2875694e616797f0dc4b7fd5ffef0e4115adb7b829ef518b6a79bd05372f827001eb4bd4936a26e729da4c6a23a1f5114f112e987
6
+ metadata.gz: 224f8a43b2a67b80a79601f1ed7fa3ad8dafe72e0eac831e0098b8e4edd1a02a1ea08839d5e5d02a6175c1b15110a74ec62a12cd519ddc667ec0e7f8acacab38
7
+ data.tar.gz: 5c61397c08ad8b02280b64e5e35728e06e02da0c4f092b4ce337b468ed83b4ac4070e911fe9dec2890ed7330646ee988ca320129861f6557e228b5cc16ca528d
@@ -17,10 +17,14 @@ you can call the tool from the console with default parameters like so
17
17
 
18
18
  magic_frozen_string_literal
19
19
 
20
- this will prepend every ".rb" file in the working directory (recursively) with the following line:
20
+ this will prepend every ".rb", ".rake", ".rabl", ".jbuilder", ".haml", ".erb" file in the working directory (recursively)
21
+ with the following magic comment followed by a blank line:
21
22
 
22
23
  # frozen_string_literal: true
23
24
 
25
+ (".haml" files will have a "-" prefix before comment and no blank line after.
26
+ ".erb" files will have the comment inside <% ... %> and no blank line after.)
27
+
24
28
  Notes:
25
29
  - existing frozen_string_literal magic comments are replaced
26
30
  - the rest of the file remains unchanged
@@ -3,17 +3,18 @@
3
3
  # A simple library to prepend magic comments to all Ruby files in a given folder
4
4
 
5
5
  module AddMagicComment
6
- MAGIC_COMMENT_PREFIX = "frozen_string_literal"
6
+ MAGIC_COMMENT_PREFIX = "frozen_string_literal".freeze
7
7
  MAGIC_COMMENT_PATTERN = /^(-|(<%))?#\s*#{MAGIC_COMMENT_PREFIX}\s*(%>)?/
8
- MAGIC_COMMENT = "#{MAGIC_COMMENT_PREFIX}: true"
8
+ MAGIC_COMMENT = "#{MAGIC_COMMENT_PREFIX}: true".freeze
9
+ EMPTY_LINE_PATTERN = /^\s$/
9
10
 
10
11
  EXTENSION_COMMENTS = {
11
- "rb" => "# #{MAGIC_COMMENT}",
12
- "rake" => "# #{MAGIC_COMMENT}",
13
- "rabl" => "# #{MAGIC_COMMENT}",
14
- "jbuilder" => "# #{MAGIC_COMMENT}",
15
- "haml" => "-# #{MAGIC_COMMENT}",
16
- "erb" => "<%# #{MAGIC_COMMENT} %>"
12
+ "rb" => "# #{MAGIC_COMMENT}\n\n",
13
+ "rake" => "# #{MAGIC_COMMENT}\n\n",
14
+ "rabl" => "# #{MAGIC_COMMENT}\n\n",
15
+ "jbuilder" => "# #{MAGIC_COMMENT}\n\n",
16
+ "haml" => "-# #{MAGIC_COMMENT}\n",
17
+ "erb" => "<%# #{MAGIC_COMMENT} %>\n"
17
18
  }
18
19
 
19
20
  def self.process(argv)
@@ -28,12 +29,12 @@ module AddMagicComment
28
29
  lines = file.readlines
29
30
 
30
31
  # remove current encoding comment(s)
31
- while lines.first && lines.first.match(MAGIC_COMMENT_PATTERN)
32
+ while lines.first && lines.first.match(MAGIC_COMMENT_PATTERN) || lines.first.match(EMPTY_LINE_PATTERN)
32
33
  lines.shift
33
34
  end
34
35
 
35
36
  # set current encoding
36
- lines.insert(0, comment + "\n")
37
+ lines.insert(0, comment)
37
38
  count += 1
38
39
 
39
40
  file.pos = 0
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: magic_frozen_string_literal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Colin Kelley after Jared Roesch after Manuel Ryan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-08 00:00:00.000000000 Z
11
+ date: 2018-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -74,6 +74,6 @@ rubyforge_project:
74
74
  rubygems_version: 2.2.2
75
75
  signing_key:
76
76
  specification_version: 4
77
- summary: 'Easily add magic comments ''# frozen_string_literal: true'' to multiple
78
- Ruby source files'
77
+ summary: 'Easily add magic comments ''# frozen_string_literal: true'' followed by
78
+ a blank line to multiple Ruby source files'
79
79
  test_files: []