Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix #220] Rename Datarockets::Style to DatarocketsStyle #240

Merged
merged 4 commits into from Feb 8, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,10 @@ The format is described in [Contributing notes](CONTRIBUTING.md#changelog-entry-

## master

## Changed

* Change ```Datarockets::Style``` module to ```DatarocketsStyle``` ([@paydaylight](https://github.com/paydaylight))

## 1.0.1 (2021-02-04)

### Added
Expand Down
2 changes: 1 addition & 1 deletion bin/console
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby

require "bundler/setup"
require "datarockets/style"
require "datarockets_style"

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.
Expand Down
2 changes: 1 addition & 1 deletion config/base.yml
@@ -1,4 +1,4 @@
require: datarockets/style
require: datarockets_style

AllCops:
NewCops: enable
Expand Down
4 changes: 2 additions & 2 deletions datarockets-style.gemspec
@@ -1,10 +1,10 @@
lib = File.expand_path("lib", __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "datarockets/style/version"
require "datarockets_style/version"

Gem::Specification.new do |spec|
spec.name = "datarockets-style"
spec.version = Datarockets::Style::VERSION
spec.version = DatarocketsStyle::VERSION
spec.authors = ["Roman Dubrovsky"]
spec.email = ["r.dubrovsky@datarockets.com"]

Expand Down
14 changes: 0 additions & 14 deletions lib/datarockets/style.rb

This file was deleted.

83 changes: 0 additions & 83 deletions lib/datarockets/style/cop/layout/array_alignment_extended.rb

This file was deleted.

37 changes: 0 additions & 37 deletions lib/datarockets/style/cop/style/nested_interpolation.rb

This file was deleted.

This file was deleted.

5 changes: 0 additions & 5 deletions lib/datarockets/style/version.rb

This file was deleted.

12 changes: 12 additions & 0 deletions lib/datarockets_style.rb
@@ -0,0 +1,12 @@
require "rubocop"
require "datarockets_style/formatter/todo_list_formatter"

require "datarockets_style/version"

require "datarockets_style/cop/layout/array_alignment_extended"
require "datarockets_style/cop/style/nested_interpolation"

# Top level module for datarockets-style
module DatarocketsStyle
# Datarickors sharable config
end
81 changes: 81 additions & 0 deletions lib/datarockets_style/cop/layout/array_alignment_extended.rb
@@ -0,0 +1,81 @@
# frozen_string_literal: true

module DatarocketsStyle
module Cop
module Layout
# Here we check if the elements of a multi-line array literal are
# aligned.
#
# @example EnforcedStyle: with_first_argument (default)
# # good
#
# array = [1, 2, 3,
# 4, 5, 6]
# array = ['run',
# 'forrest',
# 'run']
#
# # bad
#
# array = [1, 2, 3,
# 4, 5, 6]
# array = ['run',
# 'forrest',
# 'run']
#
# @example EnforcedStyle: with_fixed_indentation
# # good
#
# array = [1, 2, 3,
# 4, 5, 6]
#
# # bad
#
# array = [1, 2, 3,
# 4, 5, 6]
class ArrayAlignmentExtended < RuboCop::Cop::Cop
include RuboCop::Cop::Alignment

ALIGN_PARAMS_MSG = "Align the elements of an array literal if they span more than one line."

FIXED_INDENT_MSG = "Use one level of indentation for elements " \
"following the first line of a multi-line array."

def on_array(node)
return if node.children.size < 2

check_alignment(node.children, base_column(node, node.children))
end

def autocorrect(node)
RuboCop::Cop::AlignmentCorrector.correct(processed_source, node, column_delta)
end

private

def message(_node)
fixed_indentation? ? FIXED_INDENT_MSG : ALIGN_PARAMS_MSG
end

def fixed_indentation?
cop_config["EnforcedStyle"] == "with_fixed_indentation"
end

def base_column(node, args)
fixed_indentation? ? line_indentation(node) : display_column(args.first.source_range)
end

def line_indentation(node)
lineno = target_method_lineno(node)
line = node.source_range.source_buffer.source_line(lineno)
line_indentation = /\S.*/.match(line).begin(0)
line_indentation + configured_indentation_width
end

def target_method_lineno(node)
node.loc.line
end
end
end
end
end
35 changes: 35 additions & 0 deletions lib/datarockets_style/cop/style/nested_interpolation.rb
@@ -0,0 +1,35 @@
module DatarocketsStyle
module Cop
module Style
# This cop checks nested interpolations
#
# @example
#
# # bad
# "Hello, #{user.blank? ? 'guest' : "dear #{user.name}"}"
#
# # good
# user_name = user.blank? ? 'guest' : "dear #{user.name}"
# "Hello, #{user_name}"
class NestedInterpolation < RuboCop::Cop::Cop
include RuboCop::Cop::Interpolation

MSG = "Redundant nested interpolation.".freeze

def on_interpolation(node)
node.each_descendant(:dstr) do |descendant_node|
detect_double_interpolation(descendant_node)
end
end

private

def detect_double_interpolation(node)
node.each_child_node(:begin) do |begin_node|
add_offense(begin_node)
end
end
end
end
end
end
Expand Up @@ -46,6 +46,6 @@ def finished(inspected_files)
@total_correctable_count)
output.puts

Datarockets::Style::Formatter::TodoListFormatter::ReportSummary.new(offense_list).call(output)
DatarocketsStyle::Formatter::TodoListFormatter::ReportSummary.new(offense_list).call(output)
end
end