profile
viewpoint
Brandon Weaver baweaver @square San Francisco, CA http://www.baweaver.com Ruby and Javascript at Square

baweaver/clairvoyant 17

Divine what code you meant to write to make your tests pass

baweaver/Benchpress 15

Pit a few ruby methods against eachother, and chart it for great glory

baweaver/any 13

An Any type, modeled after Scala's Any

baweaver/classtab 11

Classical Guitar Tabs from classtab.org

baweaver/actioncable_symphony 2

The ActionCable Symphony - A Symphony Orchestra played over Actioncable!

baweaver/angular-dc 1

AngularJS directives for dc.js

baweaver/activeldap.github.io 0

The souroce of http://activeldap.github.io/

baweaver/active_importer 0

Define importers that load tabular data from spreadsheets or CSV files into any ActiveRecord-like ORM.

baweaver/angular-browserify 0

Example/seed project for AngularJS with Browserify

baweaver/angular-quickstart 0

A quickstart angular seed

CommitCommentEvent
CommitCommentEvent

startedAaronC81/sord

started time in 6 days

issue commentzspencer/rbhint

Reframe from Offense to ?Flag?

You could have Hinters which hint, or matches. add_hint for as a sub for add_offense makes sense.

zspencer

comment created time in 2 months

Pull request review commentrubocop-hq/rubocop

Improving auto correction's API

+= Cop API v0 to v1 API changes+:doctype: book++== Upgrade guide++Your custom cops should continue to work in v1.++Nevertheless it is suggested that you tweak them to use the v1 API by following the following steps:++1) Your class should inherit from `RuboCop::Cop::Base` instead of `RuboCop::Cop::Cop`.++2) Locate your calls to `add_offense` and make sure that you pass as the first argument either an `AST::Node`, a `::Parser::Source::Comment` or a `::Parser::Source::Range`, and no `location:` named parameter.++[discrete]+==== Example:++[source,ruby]+----+# Before+class MySillyCop < Cop+  def on_send(node)+    if node.method_name == :-+      add_offense(node, location: :selector, message: "Be positive")+    end+  end+end++# After+class MySillyCop < Base+  def on_send(node)+    if node.method_name == :-+      add_offense(node.loc.selector, message: "Be positive")

Aha, my mistake, disregard then

marcandre

comment created time in 2 months

pull request commentrubocop-hq/rubocop

Improving auto correction's API

That could also allow for the creation of extremely succinct simple wrappers if you made another abstraction on top of this:

Corrector.on(NODE_PATTERN).replace { |n, _captures| "wrappy(#{n})" }

...but that's a topic for another ticket.

Really liking these changes in general for what potential they unlock in making things like this possible.

marcandre

comment created time in 2 months

pull request commentrubocop-hq/rubocop

Improving auto correction's API

So here's an interesting idea, what if we top-leveled common correctors?:

include Autocorrector

def on_something(node)
  return unless we_want_to_replace?

  # Replacement
  replace(node, new_code)

  # Wrapping
  wrap(node) { |n| "wrappy_method(#{n}") }

  # Inserting before or after
  insert_before(node, '#')
end

Most of these are common enough usecases and the abstractions already exist in this PR to make most of them possible. If users are attempting to auto-correct this could make them a first-class citizen, and by only having them in the Autocorrector you'd know that they exist.

Implementation may be something like:

# Autocorrector - naive implementations

def replace(node, new_node)
  add_offense(node) do |corrector|
    corrector.replace(node, new_node)
  end  
end

def wrap(node, &fn)
  replace(node, yield new_node)
end

def insert_before(node, content)
  wrap(node) { |n| "#{content}#{n}" }
end
marcandre

comment created time in 2 months

Pull request review commentrubocop-hq/rubocop

Improving auto correction's API

 end === Auto-correct  The auto-correct can help humans automatically fix offenses that have been detected.-It's necessary to define an `autocorrect` method that returns a lambda-https://github.com/whitequark/parser/blob/master/lib/parser/rewriter.rb[rewriter]-with the corrector where you can give instructions about what to do with the+It's necessary to `extend Autocorrector`.+The method `add_offense` yields a corrector object that is a thin wrapper on

Nit: It might be nice to link to the corrector class here

marcandre

comment created time in 2 months

Pull request review commentrubocop-hq/rubocop

Improving auto correction's API

+= Cop API v0 to v1 API changes+:doctype: book++== Upgrade guide++Your custom cops should continue to work in v1.++Nevertheless it is suggested that you tweak them to use the v1 API by following the following steps:++1) Your class should inherit from `RuboCop::Cop::Base` instead of `RuboCop::Cop::Cop`.++2) Locate your calls to `add_offense` and make sure that you pass as the first argument either an `AST::Node`, a `::Parser::Source::Comment` or a `::Parser::Source::Range`, and no `location:` named parameter.++[discrete]+==== Example:++[source,ruby]+----+# Before+class MySillyCop < Cop+  def on_send(node)+    if node.method_name == :-+      add_offense(node, location: :selector, message: "Be positive")+    end+  end+end++# After+class MySillyCop < Base+  def on_send(node)+    if node.method_name == :-+      add_offense(node.loc.selector, message: "Be positive")

Note for another section, but what if we had a node.selector?

marcandre

comment created time in 2 months

pull request commentrails/rails

Easier shell command selection in Rails guide

I'd noticed that those styles were not applied to pages like getting started:

https://guides.rubyonrails.org/getting_started.html

If possible we should make that consistent so the experience is the same across the site.

benoittgt

comment created time in 2 months

Pull request review commentrails/rails

Easier shell command selection in Rails guide

   document.addEventListener("turbolinks:load", function() {     Prism.highlightAll(); +    const textNodeType = 3;+    each(document.querySelectorAll("span.token.command"), function(element) {+      each(element.childNodes, function(childElement) {

It may be good to add this to a named function as well just to provide some docs and context, as from a glance I can't tell that it's removing those.

benoittgt

comment created time in 2 months

issue openedrubocop-hq/rubocop

Alias `add_offense` with `add_match`

Is your feature request related to a problem? Please describe.

With autocorrection in use for code transitions the idea that the starting code is an 'offense' may not be accurate. It may be more accurately phrased as a match of the rule we want to correct for.

These are similar to codemods from EmberJS and a newer idea to Rubocop with autocorrection features:

https://github.com/ember-codemods/ember-test-helpers-codemod

The idea that the starting code is an 'offense' does not feel correct in these circumstances.

Describe the solution you'd like

An alias for add_offense: add_match

This would be done to add clarity for code modifications while maintaining support for current rules using add_offense.

I can write the code fairly quickly for this but would want to ask the core team about ideas on this in general.

created time in 2 months

issue commentrubocop-hq/rubocop-ast

Document the Node extensions

What do you mean by extensions here? Each of the node types themselves, or the general README for this gem?

bbatsov

comment created time in 2 months

Pull request review commentrubocop-hq/rubocop-ast

Add `argument_type?` method to make it easy to recognize argument nodes

 def used?       end     end   end++  describe '#argument_type?' do+    context 'block arguments' do+      let(:src) { 'bar { |a, b = 42, *c, d: 42, **e| nil }' }++      it 'returns true for all argument types' do+        node.children[1].children.each do |arg|

You may also be able to write this as:

expect(node.arguments.children.all?(&:argument_type?)).to eq(true)

...but more of a nit

tejasbubane

comment created time in 2 months

startedrubocop-hq/rubocop-ast

started time in 2 months

issue commentrubocop-hq/rubocop

Is it time to change the name?

If there are material costs associated with this I would be glad to help pay them.

gcentauri

comment created time in 2 months

issue commentrubocop-hq/rubocop

Is it time to change the name?

I would disagree on the note that software is not political. Facebook and Palantir are key examples of this. Others have phrased this better than me above so I will leave those comments to their merits and instead discuss a few other concerns with the name.

Cops are Enforcers, not Correctors

The reasons, in addition to the negative connotation of the word "cop", that I would consider changing this is that the gem is inherently a linter and auto-corrector. I don't really think that these align well with RoboCop or the punning to RuboCop.

If we set aside the connotations for a moment a "cop" to me is an enforcer of the law, not necessarily a corrector. Perhaps this is more the role of a guide, a mentor, or something else. The goal of RuboCop is not only in highlighting the rules but providing solutions through autocorrection.

Code Modification

Perhaps one of the most powerful features of RuboCop is its autocorrect capabilities and NodePattern syntaxes. Neither are immediately discoverable or intuitive when glancing at the name of the gem.

The sheer amount of surprise I get when I mention autocorrect to other Rubyists is concerning considering how useful it can be. I feel the name can and does hide these capabilities.

Language Parity

The name, while having uniqueness, will lead to confusion for newer developers looking for a linter, code mod, or other similar tool from other languages. Much as we do when debating features for the Ruby language we take other languages naming conventions and habits into serious consideration. I believe this should be the same for common gem names.

This can present discoverability issues. Consider Net::HTTP vs Typhoeus as an example. One is very easy to find for a lot of other language-fluent developers, the other requires domain knowledge of Ruby tooling. I think Typhoeus is a much better API and enjoy using it over the native one, but the native libraries name is far more accessible when starting from zero.


Now to be abundantly clear I do think the name can be harmful to marginalized communities, and do not mean to discount those points above in the least. I merely wished to highlight other reasons why the name of this gem may not be the best fit for the purposes it serves.

gcentauri

comment created time in 2 months

pull request commentruby-concurrency/concurrent-ruby

Removes references to static Ruby versions in docs

Documentation will have to be regenerated, but avoided that to keep the diff more minimal.

baweaver

comment created time in 3 months

PR opened ruby-concurrency/concurrent-ruby

Removes references to static Ruby versions in docs

This change removes references to Ruby 2.2.0 in favor of referencing the latest version of Ruby. By referencing just core rather than core-x.y.z the Ruby docs site will forward to the latest applicable version.

+11 -11

0 comment

7 changed files

pr created time in 3 months

fork baweaver/concurrent-ruby

Modern concurrency tools including agents, futures, promises, thread pools, supervisors, and more. Inspired by Erlang, Clojure, Scala, Go, Java, JavaScript, and classic concurrency patterns.

http://www.concurrent-ruby.com

fork in 3 months

more