pragmater 7.0.0 → 8.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 39ff1bf7d56825c6ff55879809f65bb9452ba458835496116b5e0e331cfea2c7
4
- data.tar.gz: a7e2869f307d28894d0647bbfb8a3bf654283690788d8e63c4f640fef853d700
3
+ metadata.gz: d09a7c2eff13a802e8faf5b48f7f6e3a4325c3a065dcd05522cbddeffda88111
4
+ data.tar.gz: ef70a555ebcce0db9bf3826a2312995f57ee56760648d094b70a7c06862b5b8b
5
5
  SHA512:
6
- metadata.gz: dd31dc04fff4fbea52f93d711b8e4872982509412247f6658dd8f19142a100f435c44b02f6aff413dfc1167e7d9498fd9b390b9d568db54a61ce6a4fff7ceb68
7
- data.tar.gz: 7544143fc6176e9d900c49568ad514d9b160787e045073e09bc74a6dc5b85c940cecccc0198805c696d1f61c52c161920e9031bd04a5de33cef33cefd361488c
6
+ metadata.gz: 0112f5097ef02cf51c3f24b5e04be96dbbbe18165f72c1733618880f7675cd4d5c495fd635883a8e80981b828e139115b2127b82c61cff4cf1ef7a91e98ec847
7
+ data.tar.gz: 6e6b2382eb480b6ec1a52d370b66b011ef471eb0066f9ba2dad3ad9365d028f7ece0fd67585f65aeb5dfac3e863937c282b572b79b45914254dca764717cfbd2
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -1,4 +1,4 @@
1
- # Apache License
1
+ = Apache License
2
2
 
3
3
  Version 2.0, January 2004
4
4
 
@@ -6,7 +6,7 @@ http://www.apache.org/licenses
6
6
 
7
7
  TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
8
 
9
- ## 1. Definitions
9
+ == 1. Definitions
10
10
 
11
11
  "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by
12
12
  Sections 1 through 9 of this document.
@@ -54,14 +54,14 @@ Contribution."
54
54
  "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a
55
55
  Contribution has been received by Licensor and subsequently incorporated within the Work.
56
56
 
57
- ## 2. Grant of Copyright License
57
+ == 2. Grant of Copyright License
58
58
 
59
59
  Subject to the terms and conditions of this License, each Contributor hereby grants to You a
60
60
  perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to
61
61
  reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and
62
62
  distribute the Work and such Derivative Works in Source or Object form.
63
63
 
64
- ## 3. Grant of Patent License
64
+ == 3. Grant of Patent License
65
65
 
66
66
  Subject to the terms and conditions of this License, each Contributor hereby grants to You a
67
67
  perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this
@@ -74,39 +74,38 @@ a Contribution incorporated within the Work constitutes direct or contributory p
74
74
  then any patent licenses granted to You under this License for that Work shall terminate as of the
75
75
  date such litigation is filed.
76
76
 
77
- ## 4. Redistribution
77
+ == 4. Redistribution
78
78
 
79
79
  You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with
80
80
  or without modifications, and in Source or Object form, provided that You meet the following
81
81
  conditions:
82
82
 
83
- 1. You must give any other recipients of the Work or Derivative Works a copy of this License; and
83
+ . You must give any other recipients of the Work or Derivative Works a copy of this License; and
84
84
 
85
- 2. You must cause any modified files to carry prominent notices stating that You changed the
86
- files; and
85
+ . You must cause any modified files to carry prominent notices stating that You changed the files;
86
+ and
87
87
 
88
- 3. You must retain, in the Source form of any Derivative Works that You distribute, all copyright,
89
- patent, trademark, and attribution notices from the Source form of the Work, excluding those
90
- notices that do not pertain to any part of the Derivative Works; and
88
+ . You must retain, in the Source form of any Derivative Works that You distribute, all copyright,
89
+ patent, trademark, and attribution notices from the Source form of the Work, excluding those
90
+ notices that do not pertain to any part of the Derivative Works; and
91
91
 
92
- 4. If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative
93
- Works that You distribute must include a readable copy of the attribution notices contained
94
- within such NOTICE file, excluding those notices that do not pertain to any part of the
95
- Derivative Works, in at least one of the following places: within a NOTICE text file
96
- distributed as part of the Derivative Works; within the Source form or documentation, if
97
- provided along with the Derivative Works; or, within a display generated by the Derivative
98
- Works, if and wherever such third-party notices normally appear. The contents of the NOTICE
99
- file are for informational purposes only and do not modify the License. You may add Your own
100
- attribution notices within Derivative Works that You distribute, alongside or as an addendum to
101
- the NOTICE text from the Work, provided that such additional attribution notices cannot be
102
- construed as modifying the License.
92
+ . If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works
93
+ that You distribute must include a readable copy of the attribution notices contained within such
94
+ NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in
95
+ at least one of the following places: within a NOTICE text file distributed as part of the
96
+ Derivative Works; within the Source form or documentation, if provided along with the Derivative
97
+ Works; or, within a display generated by the Derivative Works, if and wherever such third-party
98
+ notices normally appear. The contents of the NOTICE file are for informational purposes only and
99
+ do not modify the License. You may add Your own attribution notices within Derivative Works that
100
+ You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such
101
+ additional attribution notices cannot be construed as modifying the License.
103
102
 
104
103
  You may add Your own copyright statement to Your modifications and may provide additional or
105
104
  different license terms and conditions for use, reproduction, or distribution of Your modifications,
106
105
  or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of
107
106
  the Work otherwise complies with the conditions stated in this License.
108
107
 
109
- ## 5. Submission of Contributions
108
+ == 5. Submission of Contributions
110
109
 
111
110
  Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the
112
111
  Work by You to the Licensor shall be under the terms and conditions of this License, without any
@@ -114,13 +113,13 @@ additional terms or conditions. Notwithstanding the above, nothing herein shall
114
113
  the terms of any separate license agreement you may have executed with Licensor regarding such
115
114
  Contributions.
116
115
 
117
- ## 6. Trademarks
116
+ == 6. Trademarks
118
117
 
119
118
  This License does not grant permission to use the trade names, trademarks, service marks, or product
120
119
  names of the Licensor, except as required for reasonable and customary use in describing the origin
121
120
  of the Work and reproducing the content of the NOTICE file.
122
121
 
123
- ## 7. Disclaimer of Warranty
122
+ == 7. Disclaimer of Warranty
124
123
 
125
124
  Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each
126
125
  Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -129,7 +128,7 @@ TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. Y
129
128
  responsible for determining the appropriateness of using or redistributing the Work and assume any
130
129
  risks associated with Your exercise of permissions under this License.
131
130
 
132
- ## 8. Limitation of Liability
131
+ == 8. Limitation of Liability
133
132
 
134
133
  In no event and under no legal theory, whether in tort (including negligence), contract, or
135
134
  otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or
@@ -139,7 +138,7 @@ License or out of the use or inability to use the Work (including but not limite
139
138
  loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial
140
139
  damages or losses), even if such Contributor has been advised of the possibility of such damages.
141
140
 
142
- ## 9. Accepting Warranty or Additional Liability
141
+ == 9. Accepting Warranty or Additional Liability
143
142
 
144
143
  While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee
145
144
  for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights
@@ -151,11 +150,11 @@ additional liability.
151
150
 
152
151
  END OF TERMS AND CONDITIONS
153
152
 
154
- Copyright 2015 [Alchemists](https://www.alchemists.io).
153
+ Copyright 2015 link:https://www.alchemists.io/team/brooke_kuhlmann[Brooke Kuhlmann].
155
154
 
156
155
  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
157
- compliance with the License. You may obtain a [copy](http://www.apache.org/licenses/LICENSE-2.0) of
158
- the License.
156
+ compliance with the License. You may obtain a link:https://www.apache.org/licenses/LICENSE-2.0[copy]
157
+ of the License.
159
158
 
160
159
  Unless required by applicable law or agreed to in writing, software distributed under the License is
161
160
  distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
@@ -0,0 +1,323 @@
1
+ :toc: macro
2
+ :toclevels: 5
3
+ :figure-caption!:
4
+
5
+ = Pragmater
6
+
7
+ [link=http://badge.fury.io/rb/pragmater]
8
+ image::https://badge.fury.io/rb/pragmater.svg[Gem Version]
9
+ [link=https://www.alchemists.io/projects/code_quality]
10
+ image::https://img.shields.io/badge/code_style-alchemists-brightgreen.svg[Alchemists Style Guide]
11
+ [link=https://circleci.com/gh/bkuhlmann/pragmater]
12
+ image::https://circleci.com/gh/bkuhlmann/pragmater.svg?style=svg[Circle CI Status]
13
+
14
+ A command line interface for managing/formatting source file
15
+ https://en.wikipedia.org/wiki/Directive_(programming)[directive pragmas] (a.k.a. _magic comments_).
16
+ Examples:
17
+
18
+ [source,ruby]
19
+ ----
20
+ #! /usr/bin/env ruby
21
+ # frozen_string_literal: true
22
+ # encoding: UTF-8
23
+ ----
24
+
25
+ With https://www.ruby-lang.org/en/news/2015/12/25/ruby-2-3-0-released[Ruby 2.3.0], frozen strings
26
+ are supported via a pragma. This gem provides an easy way to insert or remove pragmas to single or
27
+ multiple Ruby source files in order to benefit from improved memory and concurrency performance.
28
+
29
+ toc::[]
30
+
31
+ == Features
32
+
33
+ * Supports inserting a pragma or multiple pragmas to single or multiple source files.
34
+ * Supports removing pragma(s) from single or multiple source files.
35
+ * Supports file list filtering. Defaults to any file.
36
+ * Ensures duplicate pragmas never exist.
37
+ * Ensures pragmas are consistently formatted.
38
+
39
+ == Screencasts
40
+
41
+ [link=https://www.alchemists.io/screencasts/pragmater]
42
+ image::https://www.alchemists.io/images/screencasts/pragmater/cover.svg[Screencast,600,240,role=focal_point]
43
+
44
+ == Requirements
45
+
46
+ . https://www.ruby-lang.org[Ruby]
47
+
48
+ == Setup
49
+
50
+ To install, run:
51
+
52
+ [source,bash]
53
+ ----
54
+ gem install pragmater
55
+ ----
56
+
57
+ == Usage
58
+
59
+ === Command Line Interface (CLI)
60
+
61
+ From the command line, type: `pragmater --help`
62
+
63
+ ....
64
+ Pragmater - A command line interface for managing/formatting source file pragma comments.
65
+
66
+ USAGE:
67
+ -v, --version Show gem version.
68
+ -h, --help Show this message.
69
+ -c, --config [options] Manage gem configuration.
70
+ -i, --insert [PATH] Insert pragam comments into files.
71
+ -r, --remove [options] Remove pragam comments from files.
72
+
73
+ OPTIONS:
74
+
75
+ Insert/Remove:
76
+ --comments a,b,c Add pragma comments.
77
+ --includes a,b,c Add console support.
78
+
79
+ Configuration:
80
+ --edit Edit configuration.
81
+ --info Print configuration.
82
+ ....
83
+
84
+ Both the `--insert` and `--remove` commands support the same options for specifying pragmas and/or
85
+ included files. Example:
86
+
87
+ [source,bash]
88
+ ----
89
+ pragmater --insert --comments "# frozen_string_literal: true" --includes "Gemfile" "Guardfile" "Rakefile" ".gemspec" "config.ru" "bin/**/*" "**/*.rake" "**/*.rb"
90
+ ----
91
+
92
+ The `--insert` and `--remove` commands default to the current working directory so a path isn’t
93
+ necessary unless you want to run Pragmater in a directory structure other than your current working
94
+ directory.
95
+
96
+ === Customization
97
+
98
+ This gem can be configured via a global configuration: `$HOME/.config/pragmater/configuration.yml`
99
+
100
+ It can also be configured via link:https://www.alchemists.io/projects/xdg[XDG] environment
101
+ variables.
102
+
103
+ The default configuration is as follows:
104
+
105
+ [source,yaml]
106
+ ----
107
+ :insert:
108
+ :comments: []
109
+ :includes: []
110
+ :remove:
111
+ :comments: []
112
+ :includes: []
113
+ ----
114
+
115
+ Feel free to take the above configuration, modify, and save as your own custom `configuration.yml`.
116
+
117
+ The `configuration.yml` file can be configured as follows:
118
+
119
+ * `insert`: Defines global/local comments and/or file include lists when inserting pragmas. The
120
+ `comments` and `includes` options can be either a single string or an array of strings.
121
+ * `remove`: Defines global/local comments and/or file include lists when removing pragmas. The
122
+ `comments` and `includes` options can be either a single string or an array of strings.
123
+
124
+ === Available Pragmas
125
+
126
+ With Ruby 2.3 and higher, the following pragmas are available:
127
+
128
+ * `# encoding:` Defaults to `UTF-8` but any supported encoding can be used. For a list of values,
129
+ launch an IRB session and run `Encoding.name_list`.
130
+ * `# coding:` The shorthand for `# encoding:`. Supports the same values as mentioned above.
131
+ * `# frozen_string_literal:` Defaults to `false` but can take either `true` or `false` as a value.
132
+ When enabled, Ruby will throw errors when strings are used in a mutable fashion.
133
+ * `# warn_indent:` Defaults to `false` but can take either `true` or `false` as a value. When
134
+ enabled, and running Ruby with the `-w` option, it’ll throw warnings for code that isn’t indented
135
+ by two spaces.
136
+
137
+ === Syntax
138
+
139
+ The pragma syntax allows for two kinds of styles. Example:
140
+
141
+ [source,ruby]
142
+ ----
143
+ # encoding: UTF-8
144
+ # -*- encoding: UTF-8 -*-
145
+ ----
146
+
147
+ Only the former syntax is supported by this gem as the latter syntax is more verbose and requires
148
+ additional typing.
149
+
150
+ === Precedence
151
+
152
+ When different multiple pragmas are defined, they all take precedence:
153
+
154
+ [source,ruby]
155
+ ----
156
+ # encoding: binary
157
+ # frozen_string_literal: true
158
+ ----
159
+
160
+ In the above example, both _binary_ encoding and _frozen string literals_ behavior will be applied.
161
+
162
+ When defining multiple pragmas that are similar, behavior can differ based on the _kind_ of pragma
163
+ used. The following walks through each use case so you know what to expect:
164
+
165
+ [source,ruby]
166
+ ----
167
+ # encoding: binary
168
+ # encoding: UTF-8
169
+ ----
170
+
171
+ In the above example, only the _binary_ encoding will be applied while the _UTF-8_ encoding will be
172
+ ignored (same principle applies for the `coding` pragma too).
173
+
174
+ [source,ruby]
175
+ ----
176
+ # frozen_string_literal: false
177
+ # frozen_string_literal: true
178
+ ----
179
+
180
+ In the above example, frozen string literal support _will be enabled_ instead of being disabled.
181
+
182
+ [source,ruby]
183
+ ----
184
+ # warn_indent: false
185
+ # warn_indent: true
186
+ ----
187
+
188
+ In the above example, indentation warnings _will be enabled_ instead of being disabled.
189
+
190
+ === Frozen String Literals
191
+
192
+ Support for frozen string literals was added in Ruby 2.3.0. The ability to freeze strings within a
193
+ source can be done by placing a frozen string pragma at the top of each source file. Example:
194
+
195
+ [source,ruby]
196
+ ----
197
+ # frozen_string_literal: true
198
+ ----
199
+
200
+ This is great for _selective_ enablement of frozen string literals but might be too much work for
201
+ some (even with the aid of this gem). As an alternative, frozen string literals can be enabled via
202
+ the following Ruby command line option:
203
+
204
+ ....
205
+ --enable=frozen-string-literal
206
+ ....
207
+
208
+ It is important to note that, once enabled, this freezes strings program-wide – It’s an all or
209
+ nothing option.
210
+
211
+ Regardless of whether you leverage the capabilities of this gem or the Ruby command line option
212
+ mentioned above, the following Ruby command line option is available to aid debugging and tracking
213
+ down frozen string literal issues:
214
+
215
+ ....
216
+ --debug=frozen-string-literal
217
+ ....
218
+
219
+ Ruby 2.3.0 also added the following methods to the `String` class:
220
+
221
+ * `String#+@`: Answers a duplicated, mutable, string if not already frozen. Example:
222
+ +
223
+ [source,ruby]
224
+ ----
225
+ immutable = "test".freeze
226
+ mutable = +immutable
227
+ mutable.capitalize! # => "Test"
228
+ ----
229
+ * `String#-@`: Answers a immutable string if not already frozen. Example:
230
+ +
231
+ [source,ruby]
232
+ ----
233
+ mutable = "test"
234
+ immutable = -mutable
235
+ immutable.capitalize! # => FrozenError
236
+ ----
237
+
238
+ You can also use the methods, shown above, for variable initialization. Example:
239
+
240
+ [source,ruby]
241
+ ----
242
+ immutable = -"test"
243
+ mutable = +"test"
244
+ ----
245
+
246
+ 💡 The use of `+String#-@+`, specifically, was http://bit.ly/2DGAjgG[enhanced in Ruby 2.5.0] to
247
+ _deduplicate_ all instances of the same string thus reducing your memory footprint. This can be
248
+ valuable in situations where you are not using the frozen string comment and need to selectively
249
+ freeze strings.
250
+
251
+ === Consistency
252
+
253
+ As an added bonus, this gem ensures pragmas for all analyzed files are formatted in a consistent
254
+ style. This means there is always a space after the octothorpe (`#`). Here are multiple pragmas
255
+ presented together for a visual comparison:
256
+
257
+ [source,ruby]
258
+ ----
259
+ #! /usr/bin/env ruby
260
+ # encoding: UTF-8
261
+ # coding: UTF-8
262
+ # frozen_string_literal: true
263
+ # warn_indent: true
264
+ ----
265
+
266
+ One oddity to the above is the use of `# !/usr/bin/env ruby` is not allowed but `#! /usr/bin/env
267
+ ruby` is which is why spacing is slightly different for shell pragmas.
268
+
269
+ == Development
270
+
271
+ To contribute, run:
272
+
273
+ [source,bash]
274
+ ----
275
+ git clone https://github.com/bkuhlmann/pragmater.git
276
+ cd pragmater
277
+ bin/setup
278
+ ----
279
+
280
+ You can also use the IRB console for direct access to all objects:
281
+
282
+ [source,bash]
283
+ ----
284
+ bin/console
285
+ ----
286
+
287
+ == Tests
288
+
289
+ To test, run:
290
+
291
+ [source,bash]
292
+ ----
293
+ bundle exec rake
294
+ ----
295
+
296
+ == Versioning
297
+
298
+ Read link:https://semver.org[Semantic Versioning] for details. Briefly, it means:
299
+
300
+ * Major (X.y.z) - Incremented for any backwards incompatible public API changes.
301
+ * Minor (x.Y.z) - Incremented for new, backwards compatible, public API enhancements/fixes.
302
+ * Patch (x.y.Z) - Incremented for small, backwards compatible, bug fixes.
303
+
304
+ == Code of Conduct
305
+
306
+ Please note that this project is released with a link:CODE_OF_CONDUCT.adoc[CODE OF CONDUCT]. By
307
+ participating in this project you agree to abide by its terms.
308
+
309
+ == Contributions
310
+
311
+ Read link:CONTRIBUTING.adoc[CONTRIBUTING] for details.
312
+
313
+ == License
314
+
315
+ Read link:LICENSE.adoc[LICENSE] for details.
316
+
317
+ == History
318
+
319
+ Read link:CHANGES.adoc[CHANGES] for details.
320
+
321
+ == Credits
322
+
323
+ Engineered by link:https://www.alchemists.io/team/brooke_kuhlmann[Brooke Kuhlmann].