syntax_tree 3.5.0 → 3.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/gh-pages.yml +44 -16
- data/CHANGELOG.md +8 -1
- data/Gemfile.lock +2 -2
- data/README.md +28 -6
- data/lib/syntax_tree/basic_visitor.rb +1 -1
- data/lib/syntax_tree/cli.rb +49 -8
- data/lib/syntax_tree/rake/check_task.rb +7 -64
- data/lib/syntax_tree/rake/task.rb +85 -0
- data/lib/syntax_tree/rake/write_task.rb +8 -65
- data/lib/syntax_tree/version.rb +1 -1
- metadata +4 -3
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 1fc4a522e982024b0361f9635ac6f5c7e60cfbb614aab5e58861649143c1353c
         | 
| 4 | 
            +
              data.tar.gz: f42f88445e6ef91e134fcc22441c17e372028db17a2d85be9ebc6eafd227bba0
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 965a5878ac38cb5c44b867fb92a67913f505b655d25ececc73970ad6a24a1b73f13a0885a2943db5d7950acc4194355f113e4c8a680fdf00e43f024dd3cdab59
         | 
| 7 | 
            +
              data.tar.gz: 11ffd4beaec88f4b5c2af085cce12dea49368ab39b389fb16197c37d9570b25c45614881eed89dde0e8d195f64d1d284ff3713fc41a9dff0440ebea631df3afd
         | 
| @@ -1,26 +1,54 @@ | |
| 1 | 
            -
            name:  | 
| 2 | 
            -
             | 
| 1 | 
            +
            name: Deploy rdoc to GitHub Pages
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            on:
         | 
| 4 | 
            +
              push:
         | 
| 5 | 
            +
                branches:
         | 
| 6 | 
            +
                  - main
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                # Allows you to run this workflow manually from the Actions tab
         | 
| 9 | 
            +
                workflow_dispatch:
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
         | 
| 12 | 
            +
            permissions:
         | 
| 13 | 
            +
              contents: read
         | 
| 14 | 
            +
              pages: write
         | 
| 15 | 
            +
              id-token: write
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            # Allow one concurrent deployment
         | 
| 18 | 
            +
            concurrency:
         | 
| 19 | 
            +
              group: "pages"
         | 
| 20 | 
            +
              cancel-in-progress: true
         | 
| 21 | 
            +
             | 
| 3 22 | 
             
            jobs:
         | 
| 4 | 
            -
               | 
| 23 | 
            +
              # Build job
         | 
| 24 | 
            +
              build:
         | 
| 5 25 | 
             
                runs-on: ubuntu-latest
         | 
| 6 26 | 
             
                steps:
         | 
| 7 | 
            -
                  - name: Checkout | 
| 8 | 
            -
                    uses: actions/checkout@ | 
| 9 | 
            -
             | 
| 10 | 
            -
             | 
| 27 | 
            +
                  - name: Checkout
         | 
| 28 | 
            +
                    uses: actions/checkout@v3
         | 
| 29 | 
            +
                  - name: Setup Pages
         | 
| 30 | 
            +
                    uses: actions/configure-pages@v2
         | 
| 31 | 
            +
                  - name: Set up Ruby
         | 
| 11 32 | 
             
                    uses: ruby/setup-ruby@v1
         | 
| 12 33 | 
             
                    with:
         | 
| 13 34 | 
             
                      bundler-cache: true
         | 
| 14 35 | 
             
                      ruby-version: '3.1'
         | 
| 15 | 
            -
             | 
| 16 | 
            -
                  - name: Install rdoc and generate docs 🔧
         | 
| 36 | 
            +
                  - name: Generate docs
         | 
| 17 37 | 
             
                    run: |
         | 
| 18 38 | 
             
                      gem install rdoc
         | 
| 19 | 
            -
                      rdoc --main README.md --op  | 
| 20 | 
            -
                      cp -r doc  | 
| 39 | 
            +
                      rdoc --main README.md --op _site --exclude={Gemfile,Rakefile,"coverage/*","vendor/*","bin/*","test/*","tmp/*"}
         | 
| 40 | 
            +
                      cp -r doc _site/doc
         | 
| 41 | 
            +
                  - name: Upload artifact
         | 
| 42 | 
            +
                    uses: actions/upload-pages-artifact@v1
         | 
| 21 43 |  | 
| 22 | 
            -
             | 
| 23 | 
            -
             | 
| 24 | 
            -
             | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 44 | 
            +
              # Deployment job
         | 
| 45 | 
            +
              deploy:
         | 
| 46 | 
            +
                environment:
         | 
| 47 | 
            +
                  name: github-pages
         | 
| 48 | 
            +
                  url: ${{ steps.deployment.outputs.page_url }}
         | 
| 49 | 
            +
                runs-on: ubuntu-latest
         | 
| 50 | 
            +
                needs: build
         | 
| 51 | 
            +
                steps:
         | 
| 52 | 
            +
                  - name: Deploy to GitHub Pages
         | 
| 53 | 
            +
                    id: deployment
         | 
| 54 | 
            +
                    uses: actions/deploy-pages@v1
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    | @@ -6,6 +6,12 @@ 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.6.0] - 2022-09-19
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            ### Added
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            - [#158](https://github.com/ruby-syntax-tree/syntax_tree/pull/158) - Support the ability to pass `--ignore-files` to the CLI and the Rake tasks to ignore a certain pattern of files.
         | 
| 14 | 
            +
             | 
| 9 15 | 
             
            ## [3.5.0] - 2022-08-26
         | 
| 10 16 |  | 
| 11 17 | 
             
            ### Added
         | 
| @@ -344,7 +350,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a | |
| 344 350 |  | 
| 345 351 | 
             
            - 🎉 Initial release! 🎉
         | 
| 346 352 |  | 
| 347 | 
            -
            [unreleased]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v3. | 
| 353 | 
            +
            [unreleased]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v3.6.0...HEAD
         | 
| 354 | 
            +
            [3.6.0]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v3.5.0...v3.6.0
         | 
| 348 355 | 
             
            [3.5.0]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v3.4.0...v3.5.0
         | 
| 349 356 | 
             
            [3.4.0]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v3.3.0...v3.4.0
         | 
| 350 357 | 
             
            [3.3.0]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v3.2.1...v3.3.0
         | 
    
        data/Gemfile.lock
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            PATH
         | 
| 2 2 | 
             
              remote: .
         | 
| 3 3 | 
             
              specs:
         | 
| 4 | 
            -
                syntax_tree (3. | 
| 4 | 
            +
                syntax_tree (3.6.0)
         | 
| 5 5 | 
             
                  prettier_print
         | 
| 6 6 |  | 
| 7 7 | 
             
            GEM
         | 
| @@ -19,7 +19,7 @@ GEM | |
| 19 19 | 
             
                rake (13.0.6)
         | 
| 20 20 | 
             
                regexp_parser (2.5.0)
         | 
| 21 21 | 
             
                rexml (3.2.5)
         | 
| 22 | 
            -
                rubocop (1. | 
| 22 | 
            +
                rubocop (1.36.0)
         | 
| 23 23 | 
             
                  json (~> 2.3)
         | 
| 24 24 | 
             
                  parallel (~> 1.10)
         | 
| 25 25 | 
             
                  parser (>= 3.1.2.1)
         | 
    
        data/README.md
    CHANGED
    
    | @@ -40,7 +40,7 @@ It is built with only standard library dependencies. It additionally ships with | |
| 40 40 | 
             
              - [textDocument/inlayHint](#textdocumentinlayhint)
         | 
| 41 41 | 
             
              - [syntaxTree/visualizing](#syntaxtreevisualizing)
         | 
| 42 42 | 
             
            - [Plugins](#plugins)
         | 
| 43 | 
            -
              - [ | 
| 43 | 
            +
              - [Customization](#customization)
         | 
| 44 44 | 
             
              - [Languages](#languages)
         | 
| 45 45 | 
             
            - [Integration](#integration)
         | 
| 46 46 | 
             
              - [Rake](#rake)
         | 
| @@ -83,7 +83,9 @@ bundle exec stree version | |
| 83 83 |  | 
| 84 84 | 
             
            ## CLI
         | 
| 85 85 |  | 
| 86 | 
            -
            Syntax Tree ships with the `stree` CLI, which can be used to inspect and manipulate Ruby code. Below are listed all of the commands built into the CLI that you can use. | 
| 86 | 
            +
            Syntax Tree ships with the `stree` CLI, which can be used to inspect and manipulate Ruby code. Below are listed all of the commands built into the CLI that you can use.
         | 
| 87 | 
            +
             | 
| 88 | 
            +
            For many commands, file paths are accepted after the configuration options. For all of these commands, you can alternatively pass in content through STDIN or through the `-e` option to specify an inline script.
         | 
| 87 89 |  | 
| 88 90 | 
             
            ### ast
         | 
| 89 91 |  | 
| @@ -233,6 +235,12 @@ To change the print width that you are writing with, specify the `--print-width` | |
| 233 235 | 
             
            stree write --print-width=100 path/to/file.rb
         | 
| 234 236 | 
             
            ```
         | 
| 235 237 |  | 
| 238 | 
            +
            To ignore certain files from a glob (in order to make it easier to specify the filepaths), you can pass the `--ignore-files` option as an additional glob, as in:
         | 
| 239 | 
            +
             | 
| 240 | 
            +
            ```sh
         | 
| 241 | 
            +
            stree write --ignore-files='db/**/*.rb' '**/*.rb'
         | 
| 242 | 
            +
            ```
         | 
| 243 | 
            +
             | 
| 236 244 | 
             
            ### Configuration
         | 
| 237 245 |  | 
| 238 246 | 
             
            Any of the above CLI commands can also read configuration options from a `.streerc` file in the directory where the commands are executed.
         | 
| @@ -473,11 +481,11 @@ The language server additionally includes this custom request to return a textua | |
| 473 481 |  | 
| 474 482 | 
             
            ## Plugins
         | 
| 475 483 |  | 
| 476 | 
            -
            You can register additional  | 
| 484 | 
            +
            You can register additional customization and additional languages that can flow through the same CLI with Syntax Tree's plugin system. When invoking the CLI, you pass through the list of plugins with the `--plugins` options to the commands that accept them. They should be a comma-delimited list. When the CLI first starts, it will require the files corresponding to those names.
         | 
| 477 485 |  | 
| 478 | 
            -
            ###  | 
| 486 | 
            +
            ### Customization
         | 
| 479 487 |  | 
| 480 | 
            -
            To register additional  | 
| 488 | 
            +
            To register additional customization, define a file somewhere in your load path named `syntax_tree/my_plugin`. Then when invoking the CLI, you will pass `--plugins=my_plugin`. To require multiple, separate them by a comma. In this way, you can modify Syntax Tree however you would like. Some plugins ship with Syntax Tree itself. They are:
         | 
| 481 489 |  | 
| 482 490 | 
             
            * `plugin/single_quotes` - This will change all of your string literals to use single quotes instead of the default double quotes.
         | 
| 483 491 | 
             
            * `plugin/trailing_comma` - This will put trailing commas into multiline array literals, hash literals, and method calls that can support trailing commas.
         | 
| @@ -500,9 +508,12 @@ In this case, whenever the CLI encounters a filepath that ends with the given ex | |
| 500 508 |  | 
| 501 509 | 
             
            Below are listed all of the "official" language plugins hosted under the same GitHub organization, which can be used as references for how to implement other plugins.
         | 
| 502 510 |  | 
| 511 | 
            +
            * [bf](https://github.com/ruby-syntax-tree/syntax_tree-bf) for the [brainf*** language](https://esolangs.org/wiki/Brainfuck).
         | 
| 512 | 
            +
            * [css](https://github.com/ruby-syntax-tree/syntax_tree-css) for the [CSS stylesheet language](https://www.w3.org/Style/CSS/).
         | 
| 503 513 | 
             
            * [haml](https://github.com/ruby-syntax-tree/syntax_tree-haml) for the [Haml template language](https://haml.info/).
         | 
| 504 | 
            -
            * [json](https://github.com/ruby-syntax-tree/syntax_tree-json) for JSON.
         | 
| 514 | 
            +
            * [json](https://github.com/ruby-syntax-tree/syntax_tree-json) for the [JSON notation language](https://www.json.org/).
         | 
| 505 515 | 
             
            * [rbs](https://github.com/ruby-syntax-tree/syntax_tree-rbs) for the [RBS type language](https://github.com/ruby/rbs).
         | 
| 516 | 
            +
            * [xml](https://github.com/ruby-syntax-tree/syntax_tree-xml) for the [XML markup language](https://www.w3.org/XML/).
         | 
| 506 517 |  | 
| 507 518 | 
             
            ## Integration
         | 
| 508 519 |  | 
| @@ -538,6 +549,17 @@ SyntaxTree::Rake::WriteTask.new do |t| | |
| 538 549 | 
             
            end
         | 
| 539 550 | 
             
            ```
         | 
| 540 551 |  | 
| 552 | 
            +
            #### `ignore_files`
         | 
| 553 | 
            +
             | 
| 554 | 
            +
            If you want to ignore certain file patterns when running the command, you can pass the `ignore_files` option. This will be checked with `File.fnmatch?` against each filepath that the command would be run against. For example:
         | 
| 555 | 
            +
             | 
| 556 | 
            +
            ```ruby
         | 
| 557 | 
            +
            SyntaxTree::Rake::WriteTask.new do |t|
         | 
| 558 | 
            +
              t.source_files = "**/*.rb"
         | 
| 559 | 
            +
              t.ignore_files = "db/**/*.rb"
         | 
| 560 | 
            +
            end
         | 
| 561 | 
            +
            ```
         | 
| 562 | 
            +
             | 
| 541 563 | 
             
            #### `print_width`
         | 
| 542 564 |  | 
| 543 565 | 
             
            If you want to use a different print width from the default (80), you can pass that to the `print_width` field, as in:
         | 
| @@ -35,7 +35,7 @@ module SyntaxTree | |
| 35 35 |  | 
| 36 36 | 
             
                  # In some setups with Ruby you can turn off DidYouMean, so we're going to
         | 
| 37 37 | 
             
                  # respect that setting here.
         | 
| 38 | 
            -
                  if defined?(DidYouMean | 
| 38 | 
            +
                  if defined?(DidYouMean.correct_error)
         | 
| 39 39 | 
             
                    DidYouMean.correct_error(VisitMethodError, self)
         | 
| 40 40 | 
             
                  end
         | 
| 41 41 | 
             
                end
         | 
    
        data/lib/syntax_tree/cli.rb
    CHANGED
    
    | @@ -51,13 +51,15 @@ module SyntaxTree | |
| 51 51 | 
             
                  def source
         | 
| 52 52 | 
             
                    handler.read(filepath)
         | 
| 53 53 | 
             
                  end
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                  def writable?
         | 
| 56 | 
            +
                    File.writable?(filepath)
         | 
| 57 | 
            +
                  end
         | 
| 54 58 | 
             
                end
         | 
| 55 59 |  | 
| 56 60 | 
             
                # An item of work that corresponds to a script content passed via the
         | 
| 57 61 | 
             
                # command line.
         | 
| 58 62 | 
             
                class ScriptItem
         | 
| 59 | 
            -
                  FILEPATH = :script
         | 
| 60 | 
            -
             | 
| 61 63 | 
             
                  attr_reader :source
         | 
| 62 64 |  | 
| 63 65 | 
             
                  def initialize(source)
         | 
| @@ -69,7 +71,30 @@ module SyntaxTree | |
| 69 71 | 
             
                  end
         | 
| 70 72 |  | 
| 71 73 | 
             
                  def filepath
         | 
| 72 | 
            -
                     | 
| 74 | 
            +
                    :script
         | 
| 75 | 
            +
                  end
         | 
| 76 | 
            +
             | 
| 77 | 
            +
                  def writable?
         | 
| 78 | 
            +
                    false
         | 
| 79 | 
            +
                  end
         | 
| 80 | 
            +
                end
         | 
| 81 | 
            +
             | 
| 82 | 
            +
                # An item of work that correspond to the content passed in via stdin.
         | 
| 83 | 
            +
                class STDINItem
         | 
| 84 | 
            +
                  def handler
         | 
| 85 | 
            +
                    HANDLERS[".rb"]
         | 
| 86 | 
            +
                  end
         | 
| 87 | 
            +
             | 
| 88 | 
            +
                  def filepath
         | 
| 89 | 
            +
                    :stdin
         | 
| 90 | 
            +
                  end
         | 
| 91 | 
            +
             | 
| 92 | 
            +
                  def source
         | 
| 93 | 
            +
                    $stdin.read
         | 
| 94 | 
            +
                  end
         | 
| 95 | 
            +
             | 
| 96 | 
            +
                  def writable?
         | 
| 97 | 
            +
                    false
         | 
| 73 98 | 
             
                  end
         | 
| 74 99 | 
             
                end
         | 
| 75 100 |  | 
| @@ -196,7 +221,7 @@ module SyntaxTree | |
| 196 221 |  | 
| 197 222 | 
             
                    source = item.source
         | 
| 198 223 | 
             
                    formatted = item.handler.format(source, options.print_width)
         | 
| 199 | 
            -
                    File.write(filepath, formatted) if item. | 
| 224 | 
            +
                    File.write(filepath, formatted) if item.writable?
         | 
| 200 225 |  | 
| 201 226 | 
             
                    color = source == formatted ? Color.gray(filepath) : filepath
         | 
| 202 227 | 
             
                    delta = ((Time.now - start) * 1000).round
         | 
| @@ -258,9 +283,14 @@ module SyntaxTree | |
| 258 283 | 
             
                # responsible for parsing the list and then returning the file paths at the
         | 
| 259 284 | 
             
                # end.
         | 
| 260 285 | 
             
                class Options
         | 
| 261 | 
            -
                  attr_reader : | 
| 286 | 
            +
                  attr_reader :ignore_files,
         | 
| 287 | 
            +
                              :plugins,
         | 
| 288 | 
            +
                              :print_width,
         | 
| 289 | 
            +
                              :scripts,
         | 
| 290 | 
            +
                              :target_ruby_version
         | 
| 262 291 |  | 
| 263 292 | 
             
                  def initialize(print_width: DEFAULT_PRINT_WIDTH)
         | 
| 293 | 
            +
                    @ignore_files = ""
         | 
| 264 294 | 
             
                    @plugins = []
         | 
| 265 295 | 
             
                    @print_width = print_width
         | 
| 266 296 | 
             
                    @scripts = []
         | 
| @@ -279,6 +309,13 @@ module SyntaxTree | |
| 279 309 |  | 
| 280 310 | 
             
                  def parser
         | 
| 281 311 | 
             
                    OptionParser.new do |opts|
         | 
| 312 | 
            +
                      # If there is a glob specified to ignore, then we'll track that here.
         | 
| 313 | 
            +
                      # Any of the CLI commands that operate on filenames will then ignore
         | 
| 314 | 
            +
                      # this set of files.
         | 
| 315 | 
            +
                      opts.on("--ignore-files=GLOB") do |glob|
         | 
| 316 | 
            +
                        @ignore_files = glob.match(/\A'(.*)'\z/) ? $1 : glob
         | 
| 317 | 
            +
                      end
         | 
| 318 | 
            +
             | 
| 282 319 | 
             
                      # If there are any plugins specified on the command line, then load
         | 
| 283 320 | 
             
                      # them by requiring them here. We do this by transforming something
         | 
| 284 321 | 
             
                      # like
         | 
| @@ -386,7 +423,7 @@ module SyntaxTree | |
| 386 423 | 
             
                        return 1
         | 
| 387 424 | 
             
                      end
         | 
| 388 425 |  | 
| 389 | 
            -
                    # If we're not reading from stdin and the user didn't supply  | 
| 426 | 
            +
                    # If we're not reading from stdin and the user didn't supply any
         | 
| 390 427 | 
             
                    # filepaths to be read, then we exit with the usage message.
         | 
| 391 428 | 
             
                    if $stdin.tty? && arguments.empty? && options.scripts.empty?
         | 
| 392 429 | 
             
                      warn(HELP)
         | 
| @@ -403,12 +440,16 @@ module SyntaxTree | |
| 403 440 | 
             
                        Dir
         | 
| 404 441 | 
             
                          .glob(pattern)
         | 
| 405 442 | 
             
                          .each do |filepath|
         | 
| 406 | 
            -
                             | 
| 443 | 
            +
                            if File.readable?(filepath) &&
         | 
| 444 | 
            +
                                 !File.fnmatch?(options.ignore_files, filepath)
         | 
| 445 | 
            +
                              queue << FileItem.new(filepath)
         | 
| 446 | 
            +
                            end
         | 
| 407 447 | 
             
                          end
         | 
| 408 448 | 
             
                      end
         | 
| 449 | 
            +
             | 
| 409 450 | 
             
                      options.scripts.each { |script| queue << ScriptItem.new(script) }
         | 
| 410 451 | 
             
                    else
         | 
| 411 | 
            -
                      queue <<  | 
| 452 | 
            +
                      queue << STDINItem.new
         | 
| 412 453 | 
             
                    end
         | 
| 413 454 |  | 
| 414 455 | 
             
                    # At the end, we're going to return whether or not this worker ever
         | 
| @@ -1,10 +1,6 @@ | |
| 1 1 | 
             
            # frozen_string_literal: true
         | 
| 2 2 |  | 
| 3 | 
            -
             | 
| 4 | 
            -
            require "rake/tasklib"
         | 
| 5 | 
            -
             | 
| 6 | 
            -
            require "syntax_tree"
         | 
| 7 | 
            -
            require "syntax_tree/cli"
         | 
| 3 | 
            +
            require_relative "task"
         | 
| 8 4 |  | 
| 9 5 | 
             
            module SyntaxTree
         | 
| 10 6 | 
             
              module Rake
         | 
| @@ -12,74 +8,21 @@ module SyntaxTree | |
| 12 8 | 
             
                #
         | 
| 13 9 | 
             
                # Example:
         | 
| 14 10 | 
             
                #
         | 
| 15 | 
            -
                #   require  | 
| 11 | 
            +
                #   require "syntax_tree/rake/check_task"
         | 
| 16 12 | 
             
                #
         | 
| 17 13 | 
             
                #   SyntaxTree::Rake::CheckTask.new do |t|
         | 
| 18 | 
            -
                #     t.source_files =  | 
| 14 | 
            +
                #     t.source_files = "{app,config,lib}/**/*.rb"
         | 
| 19 15 | 
             
                #   end
         | 
| 20 16 | 
             
                #
         | 
| 21 17 | 
             
                # This will create task that can be run with:
         | 
| 22 18 | 
             
                #
         | 
| 23 | 
            -
                #   rake  | 
| 19 | 
            +
                #   rake stree:check
         | 
| 24 20 | 
             
                #
         | 
| 25 | 
            -
                class CheckTask <  | 
| 26 | 
            -
                  # Name of the task.
         | 
| 27 | 
            -
                  # Defaults to :"stree:check".
         | 
| 28 | 
            -
                  attr_accessor :name
         | 
| 29 | 
            -
             | 
| 30 | 
            -
                  # Glob pattern to match source files.
         | 
| 31 | 
            -
                  # Defaults to 'lib/**/*.rb'.
         | 
| 32 | 
            -
                  attr_accessor :source_files
         | 
| 33 | 
            -
             | 
| 34 | 
            -
                  # The set of plugins to require.
         | 
| 35 | 
            -
                  # Defaults to [].
         | 
| 36 | 
            -
                  attr_accessor :plugins
         | 
| 37 | 
            -
             | 
| 38 | 
            -
                  # Max line length.
         | 
| 39 | 
            -
                  # Defaults to 80.
         | 
| 40 | 
            -
                  attr_accessor :print_width
         | 
| 41 | 
            -
             | 
| 42 | 
            -
                  # The target Ruby version to use for formatting.
         | 
| 43 | 
            -
                  # Defaults to Gem::Version.new(RUBY_VERSION).
         | 
| 44 | 
            -
                  attr_accessor :target_ruby_version
         | 
| 45 | 
            -
             | 
| 46 | 
            -
                  def initialize(
         | 
| 47 | 
            -
                    name = :"stree:check",
         | 
| 48 | 
            -
                    source_files = ::Rake::FileList["lib/**/*.rb"],
         | 
| 49 | 
            -
                    plugins = [],
         | 
| 50 | 
            -
                    print_width = DEFAULT_PRINT_WIDTH,
         | 
| 51 | 
            -
                    target_ruby_version = Gem::Version.new(RUBY_VERSION)
         | 
| 52 | 
            -
                  )
         | 
| 53 | 
            -
                    @name = name
         | 
| 54 | 
            -
                    @source_files = source_files
         | 
| 55 | 
            -
                    @plugins = plugins
         | 
| 56 | 
            -
                    @print_width = print_width
         | 
| 57 | 
            -
                    @target_ruby_version = target_ruby_version
         | 
| 58 | 
            -
             | 
| 59 | 
            -
                    yield self if block_given?
         | 
| 60 | 
            -
                    define_task
         | 
| 61 | 
            -
                  end
         | 
| 62 | 
            -
             | 
| 21 | 
            +
                class CheckTask < Task
         | 
| 63 22 | 
             
                  private
         | 
| 64 23 |  | 
| 65 | 
            -
                  def  | 
| 66 | 
            -
                     | 
| 67 | 
            -
                    task(name) { run_task }
         | 
| 68 | 
            -
                  end
         | 
| 69 | 
            -
             | 
| 70 | 
            -
                  def run_task
         | 
| 71 | 
            -
                    arguments = ["check"]
         | 
| 72 | 
            -
                    arguments << "--plugins=#{plugins.join(",")}" if plugins.any?
         | 
| 73 | 
            -
             | 
| 74 | 
            -
                    if print_width != DEFAULT_PRINT_WIDTH
         | 
| 75 | 
            -
                      arguments << "--print-width=#{print_width}"
         | 
| 76 | 
            -
                    end
         | 
| 77 | 
            -
             | 
| 78 | 
            -
                    if target_ruby_version != Gem::Version.new(RUBY_VERSION)
         | 
| 79 | 
            -
                      arguments << "--target-ruby-version=#{target_ruby_version}"
         | 
| 80 | 
            -
                    end
         | 
| 81 | 
            -
             | 
| 82 | 
            -
                    SyntaxTree::CLI.run(arguments + Array(source_files))
         | 
| 24 | 
            +
                  def command
         | 
| 25 | 
            +
                    "check"
         | 
| 83 26 | 
             
                  end
         | 
| 84 27 | 
             
                end
         | 
| 85 28 | 
             
              end
         | 
| @@ -0,0 +1,85 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require "rake"
         | 
| 4 | 
            +
            require "rake/tasklib"
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            require "syntax_tree"
         | 
| 7 | 
            +
            require "syntax_tree/cli"
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            module SyntaxTree
         | 
| 10 | 
            +
              module Rake
         | 
| 11 | 
            +
                # A parent Rake task that runs a command on a set of source files.
         | 
| 12 | 
            +
                class Task < ::Rake::TaskLib
         | 
| 13 | 
            +
                  # Name of the task.
         | 
| 14 | 
            +
                  attr_accessor :name
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                  # Glob pattern to match source files.
         | 
| 17 | 
            +
                  # Defaults to 'lib/**/*.rb'.
         | 
| 18 | 
            +
                  attr_accessor :source_files
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                  # The set of plugins to require.
         | 
| 21 | 
            +
                  # Defaults to [].
         | 
| 22 | 
            +
                  attr_accessor :plugins
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                  # Max line length.
         | 
| 25 | 
            +
                  # Defaults to 80.
         | 
| 26 | 
            +
                  attr_accessor :print_width
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                  # The target Ruby version to use for formatting.
         | 
| 29 | 
            +
                  # Defaults to Gem::Version.new(RUBY_VERSION).
         | 
| 30 | 
            +
                  attr_accessor :target_ruby_version
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                  # Glob pattern to ignore source files.
         | 
| 33 | 
            +
                  # Defaults to ''.
         | 
| 34 | 
            +
                  attr_accessor :ignore_files
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                  def initialize(
         | 
| 37 | 
            +
                    name = :"stree:#{command}",
         | 
| 38 | 
            +
                    source_files = ::Rake::FileList["lib/**/*.rb"],
         | 
| 39 | 
            +
                    plugins = [],
         | 
| 40 | 
            +
                    print_width = DEFAULT_PRINT_WIDTH,
         | 
| 41 | 
            +
                    target_ruby_version = Gem::Version.new(RUBY_VERSION),
         | 
| 42 | 
            +
                    ignore_files = ""
         | 
| 43 | 
            +
                  )
         | 
| 44 | 
            +
                    @name = name
         | 
| 45 | 
            +
                    @source_files = source_files
         | 
| 46 | 
            +
                    @plugins = plugins
         | 
| 47 | 
            +
                    @print_width = print_width
         | 
| 48 | 
            +
                    @target_ruby_version = target_ruby_version
         | 
| 49 | 
            +
                    @ignore_files = ignore_files
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                    yield self if block_given?
         | 
| 52 | 
            +
                    define_task
         | 
| 53 | 
            +
                  end
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                  private
         | 
| 56 | 
            +
             | 
| 57 | 
            +
                  # This method needs to be overridden in the child tasks.
         | 
| 58 | 
            +
                  def command
         | 
| 59 | 
            +
                    raise NotImplementedError
         | 
| 60 | 
            +
                  end
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                  def define_task
         | 
| 63 | 
            +
                    desc "Runs `stree #{command}` over source files"
         | 
| 64 | 
            +
                    task(name) { run_task }
         | 
| 65 | 
            +
                  end
         | 
| 66 | 
            +
             | 
| 67 | 
            +
                  def run_task
         | 
| 68 | 
            +
                    arguments = [command]
         | 
| 69 | 
            +
                    arguments << "--plugins=#{plugins.join(",")}" if plugins.any?
         | 
| 70 | 
            +
             | 
| 71 | 
            +
                    if print_width != DEFAULT_PRINT_WIDTH
         | 
| 72 | 
            +
                      arguments << "--print-width=#{print_width}"
         | 
| 73 | 
            +
                    end
         | 
| 74 | 
            +
             | 
| 75 | 
            +
                    if target_ruby_version != Gem::Version.new(RUBY_VERSION)
         | 
| 76 | 
            +
                      arguments << "--target-ruby-version=#{target_ruby_version}"
         | 
| 77 | 
            +
                    end
         | 
| 78 | 
            +
             | 
| 79 | 
            +
                    arguments << "--ignore-files=#{ignore_files}" if ignore_files != ""
         | 
| 80 | 
            +
             | 
| 81 | 
            +
                    SyntaxTree::CLI.run(arguments + Array(source_files))
         | 
| 82 | 
            +
                  end
         | 
| 83 | 
            +
                end
         | 
| 84 | 
            +
              end
         | 
| 85 | 
            +
            end
         | 
| @@ -1,85 +1,28 @@ | |
| 1 1 | 
             
            # frozen_string_literal: true
         | 
| 2 2 |  | 
| 3 | 
            -
             | 
| 4 | 
            -
            require "rake/tasklib"
         | 
| 5 | 
            -
             | 
| 6 | 
            -
            require "syntax_tree"
         | 
| 7 | 
            -
            require "syntax_tree/cli"
         | 
| 3 | 
            +
            require_relative "task"
         | 
| 8 4 |  | 
| 9 5 | 
             
            module SyntaxTree
         | 
| 10 6 | 
             
              module Rake
         | 
| 11 | 
            -
                # A Rake task that runs  | 
| 7 | 
            +
                # A Rake task that runs write on a set of source files.
         | 
| 12 8 | 
             
                #
         | 
| 13 9 | 
             
                # Example:
         | 
| 14 10 | 
             
                #
         | 
| 15 | 
            -
                #   require  | 
| 11 | 
            +
                #   require "syntax_tree/rake/write_task"
         | 
| 16 12 | 
             
                #
         | 
| 17 13 | 
             
                #   SyntaxTree::Rake::WriteTask.new do |t|
         | 
| 18 | 
            -
                #     t.source_files =  | 
| 14 | 
            +
                #     t.source_files = "{app,config,lib}/**/*.rb"
         | 
| 19 15 | 
             
                #   end
         | 
| 20 16 | 
             
                #
         | 
| 21 17 | 
             
                # This will create task that can be run with:
         | 
| 22 18 | 
             
                #
         | 
| 23 | 
            -
                #   rake  | 
| 19 | 
            +
                #   rake stree:write
         | 
| 24 20 | 
             
                #
         | 
| 25 | 
            -
                class WriteTask <  | 
| 26 | 
            -
                  # Name of the task.
         | 
| 27 | 
            -
                  # Defaults to :"stree:write".
         | 
| 28 | 
            -
                  attr_accessor :name
         | 
| 29 | 
            -
             | 
| 30 | 
            -
                  # Glob pattern to match source files.
         | 
| 31 | 
            -
                  # Defaults to 'lib/**/*.rb'.
         | 
| 32 | 
            -
                  attr_accessor :source_files
         | 
| 33 | 
            -
             | 
| 34 | 
            -
                  # The set of plugins to require.
         | 
| 35 | 
            -
                  # Defaults to [].
         | 
| 36 | 
            -
                  attr_accessor :plugins
         | 
| 37 | 
            -
             | 
| 38 | 
            -
                  # Max line length.
         | 
| 39 | 
            -
                  # Defaults to 80.
         | 
| 40 | 
            -
                  attr_accessor :print_width
         | 
| 41 | 
            -
             | 
| 42 | 
            -
                  # The target Ruby version to use for formatting.
         | 
| 43 | 
            -
                  # Defaults to Gem::Version.new(RUBY_VERSION).
         | 
| 44 | 
            -
                  attr_accessor :target_ruby_version
         | 
| 45 | 
            -
             | 
| 46 | 
            -
                  def initialize(
         | 
| 47 | 
            -
                    name = :"stree:write",
         | 
| 48 | 
            -
                    source_files = ::Rake::FileList["lib/**/*.rb"],
         | 
| 49 | 
            -
                    plugins = [],
         | 
| 50 | 
            -
                    print_width = DEFAULT_PRINT_WIDTH,
         | 
| 51 | 
            -
                    target_ruby_version = Gem::Version.new(RUBY_VERSION)
         | 
| 52 | 
            -
                  )
         | 
| 53 | 
            -
                    @name = name
         | 
| 54 | 
            -
                    @source_files = source_files
         | 
| 55 | 
            -
                    @plugins = plugins
         | 
| 56 | 
            -
                    @print_width = print_width
         | 
| 57 | 
            -
                    @target_ruby_version = target_ruby_version
         | 
| 58 | 
            -
             | 
| 59 | 
            -
                    yield self if block_given?
         | 
| 60 | 
            -
                    define_task
         | 
| 61 | 
            -
                  end
         | 
| 62 | 
            -
             | 
| 21 | 
            +
                class WriteTask < Task
         | 
| 63 22 | 
             
                  private
         | 
| 64 23 |  | 
| 65 | 
            -
                  def  | 
| 66 | 
            -
                     | 
| 67 | 
            -
                    task(name) { run_task }
         | 
| 68 | 
            -
                  end
         | 
| 69 | 
            -
             | 
| 70 | 
            -
                  def run_task
         | 
| 71 | 
            -
                    arguments = ["write"]
         | 
| 72 | 
            -
                    arguments << "--plugins=#{plugins.join(",")}" if plugins.any?
         | 
| 73 | 
            -
             | 
| 74 | 
            -
                    if print_width != DEFAULT_PRINT_WIDTH
         | 
| 75 | 
            -
                      arguments << "--print-width=#{print_width}"
         | 
| 76 | 
            -
                    end
         | 
| 77 | 
            -
             | 
| 78 | 
            -
                    if target_ruby_version != Gem::Version.new(RUBY_VERSION)
         | 
| 79 | 
            -
                      arguments << "--target-ruby-version=#{target_ruby_version}"
         | 
| 80 | 
            -
                    end
         | 
| 81 | 
            -
             | 
| 82 | 
            -
                    SyntaxTree::CLI.run(arguments + Array(source_files))
         | 
| 24 | 
            +
                  def command
         | 
| 25 | 
            +
                    "write"
         | 
| 83 26 | 
             
                  end
         | 
| 84 27 | 
             
                end
         | 
| 85 28 | 
             
              end
         | 
    
        data/lib/syntax_tree/version.rb
    CHANGED
    
    
    
        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. | 
| 4 | 
            +
              version: 3.6.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- | 
| 11 | 
            +
            date: 2022-09-19 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: prettier_print
         | 
| @@ -132,6 +132,7 @@ files: | |
| 132 132 | 
             
            - lib/syntax_tree/plugin/single_quotes.rb
         | 
| 133 133 | 
             
            - lib/syntax_tree/plugin/trailing_comma.rb
         | 
| 134 134 | 
             
            - lib/syntax_tree/rake/check_task.rb
         | 
| 135 | 
            +
            - lib/syntax_tree/rake/task.rb
         | 
| 135 136 | 
             
            - lib/syntax_tree/rake/write_task.rb
         | 
| 136 137 | 
             
            - lib/syntax_tree/rake_tasks.rb
         | 
| 137 138 | 
             
            - lib/syntax_tree/version.rb
         | 
| @@ -161,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 161 162 | 
             
                - !ruby/object:Gem::Version
         | 
| 162 163 | 
             
                  version: '0'
         | 
| 163 164 | 
             
            requirements: []
         | 
| 164 | 
            -
            rubygems_version: 3.3. | 
| 165 | 
            +
            rubygems_version: 3.3.21
         | 
| 165 166 | 
             
            signing_key:
         | 
| 166 167 | 
             
            specification_version: 4
         | 
| 167 168 | 
             
            summary: A parser based on ripper
         |