axr 0.5.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5c51859d7fd901aa0da185f5fa5a176bc6d6e177bbaa1a8f3d7e10f5aa65f1e7
4
+ data.tar.gz: 67e05aea13a6d3ac1399212f09c3b7768a5c76affc4d397a382a9fd43f4ba9c9
5
+ SHA512:
6
+ metadata.gz: 7de34cef752456c2cc603f70ba36ddc4088ac1cb89c0dcf2b2231c73e7112042b7b2a7db201cd99d037a42f0e467649daffe8dca0556cf7d7cdddf16da44057b
7
+ data.tar.gz: 27e72299bb4860cda3d92285a62b1f2e9efd9502f03619b4b3eb454b0c6f1691c5ab8718f98e3441c3ff74ad4267e1526b1175b1dcbae8eab868b026ad1109ef
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,37 @@
1
+ require: rubocop-rails
2
+
3
+ AllCops:
4
+ TargetRubyVersion: 2.6
5
+ Exclude:
6
+ - bin/*
7
+ - Guardfile
8
+
9
+ Style/Documentation:
10
+ Enabled: false
11
+
12
+ Metrics/LineLength:
13
+ Max: 120
14
+
15
+ Metrics/BlockLength:
16
+ ExcludedMethods: [
17
+ 'describe', 'xdescribe', 'context', 'xcontext', 'it', 'xit', 'let', 'before', 'after', 'aggregate_failures'
18
+ ]
19
+
20
+
21
+ Metrics/MethodLength:
22
+ Max: 15
23
+
24
+ Metrics/ClassLength:
25
+ Max: 150
26
+
27
+ Layout/HashAlignment:
28
+ EnforcedColonStyle: table
29
+ EnforcedHashRocketStyle: table
30
+
31
+ Lint/AmbiguousBlockAssociation:
32
+ Exclude:
33
+ - 'spec/*'
34
+ - 'spec/**/*'
35
+ - 'spec/***/**/*'
36
+ - 'spec/****/***/**/*'
37
+ - 'spec/*****/****/***/*'
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.3
7
+ before_install: gem install bundler -v 2.0.2
@@ -0,0 +1 @@
1
+ # CHANGELOG
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at sveredyuk@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in axr.gemspec
6
+ gemspec
@@ -0,0 +1,90 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ axr (0.5.0)
5
+ colorize (~> 0.8.1)
6
+ thor (~> 0.20)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ ast (2.4.0)
12
+ coderay (1.1.2)
13
+ colorize (0.8.1)
14
+ diff-lcs (1.3)
15
+ ffi (1.11.1)
16
+ formatador (0.2.5)
17
+ guard (2.16.1)
18
+ formatador (>= 0.2.4)
19
+ listen (>= 2.7, < 4.0)
20
+ lumberjack (>= 1.0.12, < 2.0)
21
+ nenv (~> 0.1)
22
+ notiffany (~> 0.0)
23
+ pry (>= 0.9.12)
24
+ shellany (~> 0.0)
25
+ thor (>= 0.18.1)
26
+ guard-compat (1.2.1)
27
+ guard-rspec (4.7.3)
28
+ guard (~> 2.1)
29
+ guard-compat (~> 1.1)
30
+ rspec (>= 2.99.0, < 4.0)
31
+ jaro_winkler (1.5.4)
32
+ listen (3.2.0)
33
+ rb-fsevent (~> 0.10, >= 0.10.3)
34
+ rb-inotify (~> 0.9, >= 0.9.10)
35
+ lumberjack (1.0.13)
36
+ method_source (0.9.2)
37
+ nenv (0.3.0)
38
+ notiffany (0.1.3)
39
+ nenv (~> 0.1)
40
+ shellany (~> 0.0)
41
+ parallel (1.18.0)
42
+ parser (2.6.5.0)
43
+ ast (~> 2.4.0)
44
+ pry (0.12.2)
45
+ coderay (~> 1.1.0)
46
+ method_source (~> 0.9.0)
47
+ rainbow (3.0.0)
48
+ rake (10.5.0)
49
+ rb-fsevent (0.10.3)
50
+ rb-inotify (0.10.0)
51
+ ffi (~> 1.0)
52
+ rspec (3.9.0)
53
+ rspec-core (~> 3.9.0)
54
+ rspec-expectations (~> 3.9.0)
55
+ rspec-mocks (~> 3.9.0)
56
+ rspec-core (3.9.0)
57
+ rspec-support (~> 3.9.0)
58
+ rspec-expectations (3.9.0)
59
+ diff-lcs (>= 1.2.0, < 2.0)
60
+ rspec-support (~> 3.9.0)
61
+ rspec-mocks (3.9.0)
62
+ diff-lcs (>= 1.2.0, < 2.0)
63
+ rspec-support (~> 3.9.0)
64
+ rspec-support (3.9.0)
65
+ rubocop (0.76.0)
66
+ jaro_winkler (~> 1.5.1)
67
+ parallel (~> 1.10)
68
+ parser (>= 2.6)
69
+ rainbow (>= 2.2.2, < 4.0)
70
+ ruby-progressbar (~> 1.7)
71
+ unicode-display_width (>= 1.4.0, < 1.7)
72
+ ruby-progressbar (1.10.1)
73
+ shellany (0.0.1)
74
+ thor (0.20.3)
75
+ unicode-display_width (1.6.0)
76
+
77
+ PLATFORMS
78
+ ruby
79
+
80
+ DEPENDENCIES
81
+ axr!
82
+ bundler (~> 2.0)
83
+ guard-rspec (~> 4.7.3)
84
+ pry (~> 0.12.2)
85
+ rake (~> 10.0)
86
+ rspec (~> 3.0)
87
+ rubocop (~> 0.76.0)
88
+
89
+ BUNDLED WITH
90
+ 2.0.2
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ # A sample Guardfile
4
+ # More info at https://github.com/guard/guard#readme
5
+
6
+ ## Uncomment and set this to only include directories you want to watch
7
+ # directories %w(app lib config test spec features) \
8
+ # .select{|d| Dir.exist?(d) ? d : UI.warning("Directory #{d} does not exist")}
9
+
10
+ ## Note: if you are using the `directories` clause above and you are not
11
+ ## watching the project directory ('.'), then you will want to move
12
+ ## the Guardfile to a watched dir and symlink it back, e.g.
13
+ #
14
+ # $ mkdir config
15
+ # $ mv Guardfile config/
16
+ # $ ln -s config/Guardfile .
17
+ #
18
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
19
+
20
+ # Note: The cmd option is now required due to the increasing number of ways
21
+ # rspec may be run, below are examples of the most common uses.
22
+ # * bundler: 'bundle exec rspec'
23
+ # * bundler binstubs: 'bin/rspec'
24
+ # * spring: 'bin/rspec' (This will use spring if running and you have
25
+ # installed the spring binstubs per the docs)
26
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
27
+ # * 'just' rspec: 'rspec'
28
+
29
+ guard :rspec, cmd: 'bundle exec rspec' do
30
+ require 'guard/rspec/dsl'
31
+ dsl = Guard::RSpec::Dsl.new(self)
32
+
33
+ # Feel free to open issues for suggestions and improvements
34
+
35
+ # RSpec files
36
+ rspec = dsl.rspec
37
+ watch(rspec.spec_helper) { rspec.spec_dir }
38
+ watch(rspec.spec_support) { rspec.spec_dir }
39
+ watch(rspec.spec_files)
40
+
41
+ # Ruby files
42
+ ruby = dsl.ruby
43
+ dsl.watch_spec_files_for(ruby.lib_files)
44
+
45
+ # Rails files
46
+ rails = dsl.rails(view_extensions: %w[erb haml slim])
47
+ dsl.watch_spec_files_for(rails.app_files)
48
+ dsl.watch_spec_files_for(rails.views)
49
+
50
+ watch(rails.controllers) do |m|
51
+ [
52
+ rspec.spec.call("routing/#{m[1]}_routing"),
53
+ rspec.spec.call("controllers/#{m[1]}_controller"),
54
+ rspec.spec.call("acceptance/#{m[1]}")
55
+ ]
56
+ end
57
+
58
+ # Rails config changes
59
+ watch(rails.spec_helper) { rspec.spec_dir }
60
+ watch(rails.routes) { "#{rspec.spec_dir}/routing" }
61
+ watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
62
+
63
+ # Capybara features specs
64
+ watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
65
+ watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
66
+
67
+ # Turnip features and steps
68
+ watch(%r{^spec/acceptance/(.+)\.feature$})
69
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
70
+ Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance'
71
+ end
72
+ end
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Volodya Sveredyuk
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,63 @@
1
+ # AXR
2
+
3
+ ### Ruby applications architecture for simplicity and team adoption
4
+
5
+ Architecture is hard. It’s very easy to build a complex system; much harder to build a simple and adaptable one. The code doesn't matter and coding for the sake of writing code is foolish.
6
+
7
+ Few of us get to write software that survives 5-10 years or longer. 90% of our work is garbage that becomes obsolete 1-3 years after release. Most of our work hours are wasted on features that never get shipped.
8
+
9
+ This is just reality.
10
+
11
+ (c) Me
12
+
13
+ ### Setup
14
+
15
+ ```sh
16
+ gem install axr
17
+ ```
18
+
19
+ or in your Gemfile:
20
+ ```ruby
21
+ gem 'axr', '~> 0.5'
22
+ ```
23
+
24
+ ```sh
25
+ bundle install
26
+ ```
27
+
28
+ Somewhere in your ruby app:
29
+ ```ruby
30
+ require 'axr'
31
+
32
+ AxR.app.define do
33
+ layer 'Api'
34
+ layer 'YourBusinessLogic'
35
+ layer 'Repo'
36
+ end
37
+ ```
38
+
39
+ Run `AxR` checker in console
40
+ ```sh
41
+ axr check . --load path/to/you/app/autoload.rb
42
+ ```
43
+
44
+ For rails apps
45
+ ```sh
46
+ axr check . --load config/environment
47
+ ```
48
+
49
+ Run for a specific directory
50
+ ```sh
51
+ axr lib/adapters
52
+ ```
53
+
54
+ Run for a specific file
55
+ ```sh
56
+ axr lib/adapters/youtube.rb
57
+ ```
58
+
59
+ ### How it works
60
+ ...TODO
61
+
62
+ ### TODO
63
+ - Add sublayers
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'axr/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'axr'
9
+ spec.version = AxR::VERSION
10
+ spec.authors = ['Volodya Sveredyuk']
11
+ spec.email = ['sveredyuk@gmail.com']
12
+ spec.summary = 'Code checker for AxR compliance.'
13
+ spec.description = 'Code checker for AxR compliance.'
14
+ spec.homepage = 'https://github.com/sveredyuk/axr'
15
+ spec.license = 'MIT'
16
+
17
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org/'
18
+
19
+ spec.metadata['homepage_uri'] = spec.homepage
20
+ spec.metadata['source_code_uri'] = 'https://github.com/sveredyuk/axr'
21
+ spec.metadata['changelog_uri'] = 'https://github.com/sveredyuk/axr/CHANGELOG.md'
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
+ end
28
+ spec.bindir = 'exe'
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = 'lib'
31
+
32
+ spec.add_dependency 'colorize', '~> 0.8.1'
33
+ spec.add_dependency 'thor', '~> 0.20'
34
+
35
+ spec.add_development_dependency 'bundler', '~> 2.0'
36
+ spec.add_development_dependency 'guard-rspec', '~> 4.7.3'
37
+ spec.add_development_dependency 'pry', '~> 0.12.2'
38
+ spec.add_development_dependency 'rake', '~> 10.0'
39
+ spec.add_development_dependency 'rspec', '~> 3.0'
40
+ spec.add_development_dependency 'rubocop', '~> 0.76.0'
41
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "axr"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/axr ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'axr'
6
+
7
+ AxR::CLI.start(ARGV)
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'axr/app'
4
+ require 'axr/cli'
5
+ require 'axr/runner'
6
+ require 'axr/version'
7
+
8
+ module AxR
9
+ def self.app
10
+ @app ||= App.instance
11
+ end
12
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'singleton'
4
+
5
+ require_relative 'layer'
6
+
7
+ module AxR
8
+ class App
9
+ include Singleton
10
+
11
+ LayerConflictError = Class.new(StandardError)
12
+
13
+ attr_reader :layers
14
+
15
+ def initialize
16
+ @layers = []
17
+ end
18
+
19
+ def define(&block)
20
+ instance_eval(&block)
21
+ end
22
+
23
+ def layer(layer_name, options = {})
24
+ check_name_conflict!(layer_name)
25
+
26
+ layers << AxR::Layer.new(layer_name, layers.size, options)
27
+ end
28
+
29
+ def layer_names
30
+ layers.map(&:name).map(&:to_s)
31
+ end
32
+
33
+ # rubocop:disable Metrics/AbcSize
34
+ def legal?(context, dependncy)
35
+ ctx = layers.find { |l| l.name.to_s == context.to_s }
36
+ dep = layers.find { |l| l.name.to_s == dependncy.to_s }
37
+
38
+ return false unless ctx && dep
39
+ return false if ctx.isolated?
40
+ return true if ctx.familiar_with.map(&:to_s).include?(dependncy.to_s)
41
+
42
+ ctx.level < dep.level
43
+ end
44
+ # rubocop:enable Metrics/AbcSize
45
+
46
+ private
47
+
48
+ def check_name_conflict!(layer_name)
49
+ return unless layers.map(&:name).include?(layer_name)
50
+
51
+ raise LayerConflictError, "Layer #{layer_name} is already defined in the app"
52
+ end
53
+
54
+ # Use only for testing purpose!
55
+ def reset
56
+ @layers = []
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'thor'
4
+
5
+ module AxR
6
+ class CLI < Thor
7
+ desc 'check PATH', 'Start AxR runner'
8
+
9
+ option :format # TODO: Add formats
10
+ option :load # TODO: Add formats
11
+
12
+ def check(pattern = nil)
13
+ $LOAD_PATH << Dir.pwd
14
+ require options['load'] if options['load']
15
+ AxR::Runner.new(pattern).invoke
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'colorized_string'
4
+
5
+ # TODO: test output format
6
+
7
+ module AxR
8
+ module Formatters
9
+ class Base
10
+ def single_file(_scanner, _file_path)
11
+ raise NotImplementedError
12
+ end
13
+
14
+ def summary(_warnings)
15
+ raise NotImplementedError
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'colorized_string'
4
+ require_relative 'base'
5
+
6
+ # TODO: test output format
7
+ module AxR
8
+ module Formatters
9
+ class Default < Base
10
+ DOT = '.'
11
+ STAR = '*'
12
+
13
+ def single_file(scanner, _file_path)
14
+ if scanner.warnings.any?
15
+ STDOUT.print ColorizedString[STAR].colorize(:yellow)
16
+ else
17
+ STDOUT.print ColorizedString[DOT].colorize(:green)
18
+ end
19
+ end
20
+
21
+ def summary(scanned_files, files_with_warnings)
22
+ STDOUT.puts
23
+ STDOUT.puts
24
+
25
+ issues_amount = 0
26
+
27
+ files_with_warnings.each_pair do |file_path, warnings|
28
+ warnings.each do |warning|
29
+ issues_amount += 1
30
+ msg = "#{file_path}:#{warning.loc_num} # => #{warning.message}"
31
+ STDOUT.puts ColorizedString[msg].colorize(:yellow)
32
+ end
33
+ end
34
+
35
+ STDOUT.puts
36
+ STDOUT.puts
37
+ STDOUT.puts("#{scanned_files.size} files scanned. #{issues_amount} issues detected")
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AxR
4
+ class Layer
5
+ attr_reader :name, :level, :isolated, :familiar_with
6
+
7
+ def initialize(name, level, options = {})
8
+ @name = name
9
+ @level = level
10
+ @isolated = options.fetch(:isolated, false)
11
+ @familiar_with = *options.fetch(:familiar_with, [])
12
+ end
13
+
14
+ alias isolated? isolated
15
+ end
16
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'axr/scanner'
4
+ require 'axr/formatters/default'
5
+
6
+ module AxR
7
+ class Runner
8
+ DOT_RB = '.rb'
9
+
10
+ attr_reader :target, :formatter
11
+
12
+ def initialize(target = nil, formatter: AxR::Formatters::Default.new)
13
+ @target = target
14
+ @formatter = formatter
15
+ end
16
+
17
+ def invoke
18
+ files_with_warnings = files_to_scan.each_with_object({}) do |file_path, issues|
19
+ scan_result = AxR::Scanner.new(file_path: file_path).scan
20
+ issues[file_path] = scan_result.warnings if scan_result.warnings.any?
21
+ formatter.single_file(scan_result, file_path)
22
+ end
23
+
24
+ formatter.summary(files_to_scan, files_with_warnings)
25
+
26
+ # exit 1 if files_with_warnings.any?
27
+
28
+ files_with_warnings
29
+ end
30
+
31
+ def files_to_scan
32
+ @files_to_scan ||= if scan_single_file?
33
+ [target]
34
+ else
35
+ Dir.glob("#{target_dir}**/*.rb")
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ def scan_single_file?
42
+ return false unless target
43
+ return false unless target.end_with?(DOT_RB)
44
+
45
+ target
46
+ end
47
+
48
+ def target_dir
49
+ return unless target
50
+
51
+ "#{target}/"
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'scanner/detection'
4
+ require_relative 'scanner/warning'
5
+
6
+ module AxR
7
+ class Scanner
8
+ attr_reader :file_path, :context, :dependecies, :warnings
9
+
10
+ def initialize(file_path:)
11
+ @file_path = file_path
12
+ @dependecies = []
13
+ @warnings = []
14
+ @context = nil
15
+ end
16
+
17
+ # rubocop:disable Metrics/AbcSize
18
+ def scan
19
+ File.open(file_path).each.with_index do |line, index|
20
+ loc_num = index + 1
21
+
22
+ line_detection = AxR.app.layer_names.detect { |layer| line.include?(layer) }
23
+ line_detection = check_space_before(line, line_detection)
24
+ context_detection = AxR.app.layer_names.detect { |layer| line.include?("module #{layer}") }
25
+
26
+ next unless line_detection || context_detection
27
+
28
+ detect_context(context_detection, line, loc_num) if context_detection && !context
29
+ detect_dependency(line_detection, line, loc_num)
30
+ detect_warning(line_detection, line, loc_num) if context
31
+ end
32
+
33
+ self
34
+ end
35
+ # rubocop:enable Metrics/AbcSize
36
+
37
+ private
38
+
39
+ def detect_context(value, loc, loc_num)
40
+ @context = Detection.new(name: value, loc: cleanup_loc(loc), loc_num: loc_num)
41
+ end
42
+
43
+ def detect_dependency(value, loc, loc_num)
44
+ return if context && value == context.name
45
+
46
+ @dependecies << Detection.new(name: value, loc: cleanup_loc(loc), loc_num: loc_num)
47
+ end
48
+
49
+ def detect_warning(value, loc, loc_num)
50
+ return if value == context.name
51
+ return if AxR.app.legal?(context.name, value)
52
+
53
+ msg = "#{context.name} layer should not be familiar with #{value}"
54
+
55
+ @warnings << Warning.new(message: msg, loc: cleanup_loc(loc), loc_num: loc_num)
56
+ end
57
+
58
+ def cleanup_loc(loc)
59
+ loc.chomp.strip
60
+ end
61
+
62
+ SPACE = ' '
63
+
64
+ def check_space_before(line, line_detection)
65
+ return unless line_detection
66
+
67
+ line_detection if line[line.index(line_detection) - 1] == SPACE
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'axr/scanner'
4
+
5
+ module AxR
6
+ class Scanner
7
+ class Detection
8
+ attr_reader :name, :loc, :loc_num
9
+
10
+ def initialize(name:, loc:, loc_num:)
11
+ @name = name
12
+ @loc = loc
13
+ @loc_num = loc_num
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'axr/scanner'
4
+
5
+ module AxR
6
+ class Scanner
7
+ class Warning
8
+ attr_reader :message, :loc, :loc_num
9
+
10
+ def initialize(message:, loc:, loc_num:)
11
+ @message = message
12
+ @loc = loc
13
+ @loc_num = loc_num
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AxR
4
+ VERSION = '0.5.0'
5
+ end
metadata ADDED
@@ -0,0 +1,187 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: axr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ platform: ruby
6
+ authors:
7
+ - Volodya Sveredyuk
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-11-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colorize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.8.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.8.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.20'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.20'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard-rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 4.7.3
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 4.7.3
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.12.2
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.12.2
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.76.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.76.0
125
+ description: Code checker for AxR compliance.
126
+ email:
127
+ - sveredyuk@gmail.com
128
+ executables:
129
+ - axr
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - ".gitignore"
134
+ - ".rspec"
135
+ - ".rubocop.yml"
136
+ - ".travis.yml"
137
+ - CHANGELOG.md
138
+ - CODE_OF_CONDUCT.md
139
+ - Gemfile
140
+ - Gemfile.lock
141
+ - Guardfile
142
+ - LICENSE.txt
143
+ - README.md
144
+ - Rakefile
145
+ - axr.gemspec
146
+ - bin/console
147
+ - bin/setup
148
+ - exe/axr
149
+ - lib/axr.rb
150
+ - lib/axr/app.rb
151
+ - lib/axr/cli.rb
152
+ - lib/axr/formatters/base.rb
153
+ - lib/axr/formatters/default.rb
154
+ - lib/axr/layer.rb
155
+ - lib/axr/runner.rb
156
+ - lib/axr/scanner.rb
157
+ - lib/axr/scanner/detection.rb
158
+ - lib/axr/scanner/warning.rb
159
+ - lib/axr/version.rb
160
+ homepage: https://github.com/sveredyuk/axr
161
+ licenses:
162
+ - MIT
163
+ metadata:
164
+ allowed_push_host: https://rubygems.org/
165
+ homepage_uri: https://github.com/sveredyuk/axr
166
+ source_code_uri: https://github.com/sveredyuk/axr
167
+ changelog_uri: https://github.com/sveredyuk/axr/CHANGELOG.md
168
+ post_install_message:
169
+ rdoc_options: []
170
+ require_paths:
171
+ - lib
172
+ required_ruby_version: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ required_rubygems_version: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ requirements: []
183
+ rubygems_version: 3.0.6
184
+ signing_key:
185
+ specification_version: 4
186
+ summary: Code checker for AxR compliance.
187
+ test_files: []