syntax_tree 3.2.1 → 3.3.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: e903c6474622266f71a8116d7a94a5a4cc437bb16bb7543f7c7de4d23ce15764
4
- data.tar.gz: 33dd3eec6312d18285d7e1f5e04048fc0ac36dfb7fe51295ead1357f9d19c8e4
3
+ metadata.gz: 92ff69f19d5433566404bce6888eae08a442861821612c986489db05679ecd22
4
+ data.tar.gz: e05511cf866fa1e0cfde540f0a0bc84a88414b128583a37a68c73658ff667b16
5
5
  SHA512:
6
- metadata.gz: 6cd1ea0a06ad365c1f7a24c0eefe0df70a7995d173c82c60fb3ec3a06c794960f7cabbbd6521c2b44b583227ed3cd27391ffbb0f8dd4812a4493606386b4355a
7
- data.tar.gz: e42148794773a87f2dc862ff3ef346817074e6f67381cbaf248c53bbc3258d9062a073b5e5c3516ab21646276bc669adadf177d6879d862526d53d291c7be2cd
6
+ metadata.gz: 3d98f8b9a997ef9278ad2ea9c1600ee5abc52c646d157b0180f6cf6956ebde2ccc6d9ea917436231645a7d4bf58ce1627fbae393b89e81b683157bc5263d65e0
7
+ data.tar.gz: 924ccb54dec3055dca88aef5efe839d2c979abedfdf96f5e0996e18390b3e246b676cdb1c8aba6d51edfed42219bff3c80b4bfcead0eb3f6b926e585c96f0a1b
data/CHANGELOG.md CHANGED
@@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [3.3.0] - 2022-08-02
10
+
11
+ ### Added
12
+
13
+ - [#123](https://github.com/ruby-syntax-tree/syntax_tree/pull/123) - Allow the rake tasks to configure print width.
14
+ - [#125](https://github.com/ruby-syntax-tree/syntax_tree/pull/125) - Add support for an `.streerc` file in the current working directory to configure the CLI.
15
+
9
16
  ## [3.2.1] - 2022-07-22
10
17
 
11
18
  ### Changed
@@ -312,7 +319,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
312
319
 
313
320
  - 🎉 Initial release! 🎉
314
321
 
315
- [unreleased]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v3.2.1...HEAD
322
+ [unreleased]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v3.3.0...HEAD
323
+ [3.3.0]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v3.2.1...v3.3.0
316
324
  [3.2.1]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v3.2.0...v3.2.1
317
325
  [3.2.0]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v3.1.0...v3.2.0
318
326
  [3.1.0]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v3.0.1...v3.1.0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- syntax_tree (3.2.1)
4
+ syntax_tree (3.3.0)
5
5
  prettier_print
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -19,6 +19,7 @@ It is built with only standard library dependencies. It additionally ships with
19
19
  - [json](#json)
20
20
  - [match](#match)
21
21
  - [write](#write)
22
+ - [Configuration](#configuration)
22
23
  - [Library](#library)
23
24
  - [SyntaxTree.read(filepath)](#syntaxtreereadfilepath)
24
25
  - [SyntaxTree.parse(source)](#syntaxtreeparsesource)
@@ -231,6 +232,19 @@ To change the print width that you are writing with, specify the `--print-width`
231
232
  stree write --print-width=100 path/to/file.rb
232
233
  ```
233
234
 
235
+ ### Configuration
236
+
237
+ Any of the above CLI commands can also read configuration options from a `.streerc` file in the directory where the commands are executed.
238
+
239
+ This should be a text file with each argument on a separate line.
240
+
241
+ ```txt
242
+ --print-width=100
243
+ --plugins=plugin/trailing_comma
244
+ ```
245
+
246
+ If this file is present, it will _always_ be used for CLI commands. You can also pass options from the command line as in the examples above. The options in the `.streerc` file are passed to the CLI first, then the arguments from the command line. In the case of exclusive options (e.g. `--print-width`), this means that the command line options override what's in the config file. In the case of options that can take multiple inputs (e.g. `--plugins`), the effect is additive. That is, the plugins passed from the command line will be loaded _in addition to_ the plugins in the config file.
247
+
234
248
  ## Library
235
249
 
236
250
  Syntax Tree can be used as a library to access the syntax tree underlying Ruby source code.
@@ -505,6 +519,16 @@ SyntaxTree::Rake::WriteTask.new do |t|
505
519
  end
506
520
  ```
507
521
 
522
+ #### `print_width`
523
+
524
+ If you want to use a different print width from the default (80), you can pass that to the `print_width` field, as in:
525
+
526
+ ```ruby
527
+ SyntaxTree::Rake::WriteTask.new do |t|
528
+ t.print_width = 100
529
+ end
530
+ ```
531
+
508
532
  #### `plugins`
509
533
 
510
534
  If you're running Syntax Tree with plugins (either your own or the pre-built ones), you can pass that to the `plugins` field, as in:
@@ -4,6 +4,8 @@ module SyntaxTree
4
4
  # Syntax Tree ships with the `stree` CLI, which can be used to inspect and
5
5
  # manipulate Ruby code. This module is responsible for powering that CLI.
6
6
  module CLI
7
+ CONFIG_FILE = ".streerc"
8
+
7
9
  # A utility wrapper around colored strings in the output.
8
10
  class Color
9
11
  attr_reader :value, :code
@@ -269,6 +271,11 @@ module SyntaxTree
269
271
  name, *arguments = argv
270
272
  print_width = DEFAULT_PRINT_WIDTH
271
273
 
274
+ config_file = File.join(Dir.pwd, CONFIG_FILE)
275
+ if File.readable?(config_file)
276
+ arguments.unshift(*File.readlines(config_file, chomp: true))
277
+ end
278
+
272
279
  while arguments.first&.start_with?("--")
273
280
  case (argument = arguments.shift)
274
281
  when /^--plugins=(.+)$/
@@ -1978,7 +1978,7 @@ module SyntaxTree
1978
1978
  # If we hit a statements, then we're safe to use whatever since we
1979
1979
  # know for certain we're going to get split over multiple lines
1980
1980
  # anyway.
1981
- break false if parent.is_a?(Statements)
1981
+ break false if parent.is_a?(Statements) || parent.is_a?(ArgParen)
1982
1982
 
1983
1983
  [Command, CommandCall].include?(parent.class)
1984
1984
  end
@@ -35,14 +35,20 @@ module SyntaxTree
35
35
  # Defaults to [].
36
36
  attr_accessor :plugins
37
37
 
38
+ # Max line length.
39
+ # Defaults to 80.
40
+ attr_accessor :print_width
41
+
38
42
  def initialize(
39
43
  name = :"stree:check",
40
44
  source_files = ::Rake::FileList["lib/**/*.rb"],
41
- plugins = []
45
+ plugins = [],
46
+ print_width = DEFAULT_PRINT_WIDTH
42
47
  )
43
48
  @name = name
44
49
  @source_files = source_files
45
50
  @plugins = plugins
51
+ @print_width = print_width
46
52
 
47
53
  yield self if block_given?
48
54
  define_task
@@ -58,6 +64,9 @@ module SyntaxTree
58
64
  def run_task
59
65
  arguments = ["check"]
60
66
  arguments << "--plugins=#{plugins.join(",")}" if plugins.any?
67
+ if print_width != DEFAULT_PRINT_WIDTH
68
+ arguments << "--print-width=#{print_width}"
69
+ end
61
70
 
62
71
  SyntaxTree::CLI.run(arguments + Array(source_files))
63
72
  end
@@ -35,14 +35,20 @@ module SyntaxTree
35
35
  # Defaults to [].
36
36
  attr_accessor :plugins
37
37
 
38
+ # Max line length.
39
+ # Defaults to 80.
40
+ attr_accessor :print_width
41
+
38
42
  def initialize(
39
43
  name = :"stree:write",
40
44
  source_files = ::Rake::FileList["lib/**/*.rb"],
41
- plugins = []
45
+ plugins = [],
46
+ print_width = DEFAULT_PRINT_WIDTH
42
47
  )
43
48
  @name = name
44
49
  @source_files = source_files
45
50
  @plugins = plugins
51
+ @print_width = print_width
46
52
 
47
53
  yield self if block_given?
48
54
  define_task
@@ -58,6 +64,9 @@ module SyntaxTree
58
64
  def run_task
59
65
  arguments = ["write"]
60
66
  arguments << "--plugins=#{plugins.join(",")}" if plugins.any?
67
+ if print_width != DEFAULT_PRINT_WIDTH
68
+ arguments << "--print-width=#{print_width}"
69
+ end
61
70
 
62
71
  SyntaxTree::CLI.run(arguments + Array(source_files))
63
72
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SyntaxTree
4
- VERSION = "3.2.1"
4
+ VERSION = "3.3.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: syntax_tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.1
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Newton
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-07-22 00:00:00.000000000 Z
11
+ date: 2022-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: prettier_print