rubocop-netlify 0.4.0 → 0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 14ac9b91a394e30090e1f4f99216db1f5f5e13f5d6cd08a712d655305a9df733
4
- data.tar.gz: 1baf31dc8a12f876322724a2941e93bd455b813ea07abe57aa15fb311519e55b
3
+ metadata.gz: f7840def645448a07e1449ee73e06840e07fbbc3f0b98446a16f6e0dd8a9290a
4
+ data.tar.gz: af284fab249cf5746b8cdf2bee7c4391a2a5b74beecadd300c70e4b336babeba
5
5
  SHA512:
6
- metadata.gz: c1b35300934ab6fa79388c1ff2897749f34c866f1868eb005b6815b78ab7e2cf098fcbb8edca44cd400419f982e1f2fdf6c457976d742c7980b27ff4dd3b645b
7
- data.tar.gz: 50da279bb3147da507117b36421a48c9c6b93368658cae3b4527b4f4dbbbd2d1b9a2a6252321100f23cd1b8ffdd83bee7a2f5a9bb30bb3e130cef19ba187954b
6
+ metadata.gz: aa2f814950a4fb23af00edd90b1fa78eaf3c8b2889470e4b5b79bc35e3a3ce87cc07b5a961724bce2b670037150e83bcdc8924e9e74916036fbe6107442789a7
7
+ data.tar.gz: 202af5b55defcbe32e56fe189907609ac95062a21765096d7e662e6df82354fc25690b911e9ba00e10110f19c6249e618449ccf6b29d4f5954e10d69ef5e28cf
@@ -3,7 +3,8 @@ name: Dependency License Scanning
3
3
  on:
4
4
  push:
5
5
  branches:
6
- - master
6
+ - chore/fossa-workflow
7
+ - main
7
8
 
8
9
  defaults:
9
10
  run:
@@ -15,10 +16,13 @@ jobs:
15
16
  steps:
16
17
  - name: Checkout
17
18
  uses: actions/checkout@v2
18
- - name: Fossa init
19
+ - name: Download fossa cli
19
20
  run: |-
20
- curl -H 'Cache-Control: no-cache' https://raw.githubusercontent.com/fossas/fossa-cli/master/install.sh | bash
21
- fossa init
21
+ mkdir -p $HOME/.local/bin
22
+ curl https://raw.githubusercontent.com/fossas/fossa-cli/master/install.sh | bash -s -- -b $HOME/.local/bin
23
+ echo "$HOME/.local/bin" >> $GITHUB_PATH
24
+ - name: Fossa init
25
+ run: fossa init
22
26
  - name: Set env
23
27
  run: echo "line_number=$(grep -n "project" .fossa.yml | cut -f1 -d:)" >> $GITHUB_ENV
24
28
  - name: Configuration
@@ -29,3 +33,4 @@ jobs:
29
33
  run: fossa analyze --debug
30
34
  env:
31
35
  FOSSA_API_KEY: ${{ secrets.FOSSA_API_KEY }}
36
+
data/README.md CHANGED
@@ -27,3 +27,12 @@ bundle exec rake test
27
27
 
28
28
  ## The Cops
29
29
  All cops are located under [lib/rubocop/cop/netlify](lib/rubocop/cop/netlify), and contain examples/documentation.
30
+
31
+ ## Release
32
+
33
+ 1. Make sure you have an account in https://rubygems.org/ and be a part of https://rubygems.org/gems/rubocop-netlify owners
34
+ 2. Update a version in [lib/rubocop/netlify/version.rb](lib/rubocop/netlify/version.rb)
35
+ 3. Tag it (also maybe make a new release in GitHub)
36
+ 4. Run `gem build rubocop-netlify.gemspec` to build a gem
37
+ 5. Run `gem push` with a newly created gem file
38
+ 6. Done done!
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Netlify
6
+ # This cop checks for use of Rails.env to check the environment
7
+ #
8
+ # @example
9
+ # # bad
10
+ # Rails.env.production?
11
+ #
12
+ # # good
13
+ # Netlify.env.production?
14
+ class RailsEnvCheck < Cop
15
+ MSG = "Prefer using `Netlify.env` instead of `Rails.env` to check the environment"
16
+
17
+ def_node_matcher :rails_env?, <<~PATTERN
18
+ (send (send (const {nil? cbase} :Rails) :env) /staging?|production?/)
19
+ PATTERN
20
+
21
+ def on_send(node)
22
+ add_offense(node) if rails_env? node
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Netlify
6
+ class RequireScopeBase < Cop
7
+ RESTRICT_ON_SEND = [:require_scope, :public, :private, :protected]
8
+
9
+ def on_class(node)
10
+ @require_scopes = []
11
+ @method_protection = :public
12
+ @is_controller = node.identifier.short_name.to_s.end_with?("Controller")
13
+ end
14
+
15
+ def on_send(node)
16
+ if node.method_name == :require_scope
17
+ scopes = []
18
+ limits = {}
19
+ node.arguments.each do |option|
20
+ if option.is_a? RuboCop::AST::StrNode
21
+ scopes << option.value
22
+ elsif option.is_a? RuboCop::AST::HashNode
23
+ option.pairs.each do |pair|
24
+ if pair.value.is_a? RuboCop::AST::ArrayNode
25
+ limits[pair.key.value] = pair.value.values.map(&:value)
26
+ elsif pair.value.is_a? RuboCop::AST::SymbolNode
27
+ limits[pair.key.value] = [pair.value.value]
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ @require_scopes << {
34
+ scopes: scopes,
35
+ limits: limits,
36
+ node: node
37
+ }
38
+ else
39
+ @method_protection = node.method_name
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ def require_scopes_for_method(action)
46
+ matches = []
47
+ @require_scopes.each do |require_scope|
48
+ if require_scope[:limits][:only]
49
+ matches << require_scope if require_scope[:limits][:only].include?(action)
50
+ elsif require_scope[:limits][:except]
51
+ matches << require_scope unless require_scope[:limits][:except].include?(action)
52
+ else
53
+ matches << require_scope
54
+ end
55
+ end
56
+
57
+ return matches
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "require_scope_base"
4
+
5
+ module RuboCop
6
+ module Cop
7
+ module Netlify
8
+ # This cop checks OAuth scope definition duplication
9
+ #
10
+ # @example
11
+ # # bad
12
+ # require_scope "all:read"
13
+ # require_scope "public"
14
+ #
15
+ # # good
16
+ # require_scope "public", "all:read"
17
+ #
18
+ # # bad
19
+ # require_scope "all:read", only: :index
20
+ # require_scope "all:read", only: [:index, :show]
21
+ #
22
+ # # good
23
+ # require_scope "all:read", only: [:index, :show]
24
+ #
25
+ # # bad
26
+ # require_scope "all:read"
27
+ # require_scope "all:write"
28
+ #
29
+ # # good
30
+ # require_scope "??" # Be careful!
31
+ class RequireScopeDuplication < RequireScopeBase
32
+ def on_def(node)
33
+ return unless @is_controller
34
+ return unless @method_protection == :public
35
+
36
+ require_scopes = require_scopes_for_method(node.method_name)
37
+ if require_scopes.size > 1
38
+ add_offense(require_scopes.last[:node], message: "Multiple overlapping definitions: #{require_scopes.map { |rs| rs[:scopes].inspect }.join(" and ")}.")
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "require_scope_base"
4
+
5
+ module RuboCop
6
+ module Cop
7
+ module Netlify
8
+ # This cop checks OAuth scope semantic mismatches
9
+ #
10
+ # @example
11
+ # # bad
12
+ # require_scope "all:read"
13
+ # def destroy
14
+ #
15
+ # # good
16
+ # require_scope "all:read"
17
+ # def index
18
+ class RequireScopeSemantics < RequireScopeBase
19
+ WRITE_KEYWORDS = ["update", "create", "destroy", "new", "edit", "revoke", "delete"].freeze
20
+ READ_KEYWORDS = ["show", "index"].freeze
21
+
22
+ def on_def(node)
23
+ return unless @is_controller
24
+ return unless @method_protection == :public
25
+
26
+ require_scopes = require_scopes_for_method(node.method_name)
27
+ return if require_scopes.empty?
28
+ require_scope = require_scopes.last # this is the observed matching behavior
29
+ scopes = require_scope[:scopes]
30
+
31
+ if WRITE_KEYWORDS.any? { |s| node.method_name.to_s.include?(s) }
32
+ read_semantic_scopes = scopes.select { |scope| scope.include?("read") }
33
+ unless read_semantic_scopes.empty?
34
+ add_offense(node, message: format("Semantic naming mismatch between method `%s` and scope `%s`", node.method_name, read_semantic_scopes[0]))
35
+ end
36
+ end
37
+
38
+ if READ_KEYWORDS.any? { |s| node.method_name.to_s.include?(s) }
39
+ write_semantic_scopes = scopes.select { |scope| scope.include?("write") }
40
+ unless write_semantic_scopes.empty?
41
+ add_offense(node, message: format("Semantic naming mismatch between method `%s` and scope `%s`", node.method_name, write_semantic_scopes[0]))
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -3,3 +3,6 @@
3
3
  require_relative "netlify/request_tests_param_encoding"
4
4
  require_relative "netlify/sidekiq_keyword_arguments"
5
5
  require_relative "netlify/invalid_model_assignment"
6
+ require_relative "netlify/rails_env_check"
7
+ require_relative "netlify/require_scope_semantics"
8
+ require_relative "netlify/require_scope_duplication"
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Netlify
5
- VERSION = "0.4.0"
5
+ VERSION = "0.6.0"
6
6
  end
7
7
  end
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
14
14
  spec.license = "MIT"
15
15
  spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
16
16
 
17
- spec.add_dependency "rubocop", "~> 0.72", "< 2.0"
17
+ spec.add_dependency "rubocop", ">= 0.72", "< 2.0"
18
18
  spec.add_development_dependency "minitest", "~> 5.10"
19
19
 
20
20
  # Specify which files should be added to the gem when it is released.
metadata CHANGED
@@ -1,20 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-netlify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esteban Pastorino
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-29 00:00:00.000000000 Z
11
+ date: 2023-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0.72'
20
20
  - - "<"
@@ -24,7 +24,7 @@ dependencies:
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - "~>"
27
+ - - ">="
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0.72'
30
30
  - - "<"
@@ -62,7 +62,11 @@ files:
62
62
  - bin/setup
63
63
  - lib/rubocop-netlify.rb
64
64
  - lib/rubocop/cop/netlify/invalid_model_assignment.rb
65
+ - lib/rubocop/cop/netlify/rails_env_check.rb
65
66
  - lib/rubocop/cop/netlify/request_tests_param_encoding.rb
67
+ - lib/rubocop/cop/netlify/require_scope_base.rb
68
+ - lib/rubocop/cop/netlify/require_scope_duplication.rb
69
+ - lib/rubocop/cop/netlify/require_scope_semantics.rb
66
70
  - lib/rubocop/cop/netlify/sidekiq_keyword_arguments.rb
67
71
  - lib/rubocop/cop/netlify_cops.rb
68
72
  - lib/rubocop/netlify.rb