rubocop-netlify 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 72d44485aa17e77116b7740e79593c17e6c0f181850cd187e0b66aa571187374
4
- data.tar.gz: 98313e340f5d5db94a4684b8967ca6b5a62e3e64d1d46cc64f52e993beed7680
3
+ metadata.gz: f7840def645448a07e1449ee73e06840e07fbbc3f0b98446a16f6e0dd8a9290a
4
+ data.tar.gz: af284fab249cf5746b8cdf2bee7c4391a2a5b74beecadd300c70e4b336babeba
5
5
  SHA512:
6
- metadata.gz: 63a173bf1181c0dd8ea4f50e86ccc378ba63b73265e20616e6f07f6b238ac3ddce08eecd18cb6b75f0f66475a1e41a400c44139e20b72263df39b4d1ef6e14c6
7
- data.tar.gz: 20602c2ed24300084d38de95985bfc485434b167606febfbdd1d13195f697089cbccae903e74331e142bdf1c25fa7da2b6b8872c22e120cbb2175cd384aef62f
6
+ metadata.gz: aa2f814950a4fb23af00edd90b1fa78eaf3c8b2889470e4b5b79bc35e3a3ce87cc07b5a961724bce2b670037150e83bcdc8924e9e74916036fbe6107442789a7
7
+ data.tar.gz: 202af5b55defcbe32e56fe189907609ac95062a21765096d7e662e6df82354fc25690b911e9ba00e10110f19c6249e618449ccf6b29d4f5954e10d69ef5e28cf
@@ -3,8 +3,8 @@ name: Dependency License Scanning
3
3
  on:
4
4
  push:
5
5
  branches:
6
- - master
7
6
  - chore/fossa-workflow
7
+ - main
8
8
 
9
9
  defaults:
10
10
  run:
@@ -21,7 +21,6 @@ jobs:
21
21
  mkdir -p $HOME/.local/bin
22
22
  curl https://raw.githubusercontent.com/fossas/fossa-cli/master/install.sh | bash -s -- -b $HOME/.local/bin
23
23
  echo "$HOME/.local/bin" >> $GITHUB_PATH
24
-
25
24
  - name: Fossa init
26
25
  run: fossa init
27
26
  - name: Set env
@@ -34,3 +33,4 @@ jobs:
34
33
  run: fossa analyze --debug
35
34
  env:
36
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.5.0"
5
+ VERSION = "0.6.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-netlify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esteban Pastorino
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-11 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
@@ -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
@@ -72,7 +76,7 @@ homepage: https://github.com/netlify/rubocop-netlify
72
76
  licenses:
73
77
  - MIT
74
78
  metadata: {}
75
- post_install_message:
79
+ post_install_message:
76
80
  rdoc_options: []
77
81
  require_paths:
78
82
  - lib
@@ -87,8 +91,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
91
  - !ruby/object:Gem::Version
88
92
  version: '0'
89
93
  requirements: []
90
- rubygems_version: 3.0.3.1
91
- signing_key:
94
+ rubygems_version: 3.1.4
95
+ signing_key:
92
96
  specification_version: 4
93
97
  summary: RuboCop Netlify
94
98
  test_files: []