rubocop-isucon 0.2.0 → 1.0.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: 645e1a353538a4c8d8c8914ac76ac7fbb6f1338dbea8d10c16394a6711be725a
4
- data.tar.gz: 450b780a05d2e4f5632bd2ffe35453390bfa1e1c4a240662e440b5cbb2e5390c
3
+ metadata.gz: 6bd0eac249a23368414a86aa1ab08826542cf644fa50b19017a2bcfd6648d594
4
+ data.tar.gz: 18e829ac97ac7c7cb9696a1078f36b8a958fd340ddbb9bc1b232b2630e683df2
5
5
  SHA512:
6
- metadata.gz: 5c900d876a05963ec323cb6e9a4aec8b6b3b9f35c9bc76910e43c758cf0b6b5203b1d53ee2cf050a7ccfe5f304b4158f6d43a85b72441c42726270e0518b6f83
7
- data.tar.gz: 0cea7082761dd2bdc38792b0cd60fbccafa886bded25475fa848fb6c2cbab58ea3a370d5fcbb793ca02402c95aab495bfee8e63b3617f3e5b9420fde4d18070e
6
+ metadata.gz: 58238a855da0596f653d47436977b44cc7722982a1b59e60850f79003b356d85071cba061cca6adae2b4cfa4b63ab489e121135e3c2954f366f5ca1c375e1bbf
7
+ data.tar.gz: b7747989e1219c7fee4f834b8811e419d3c9f6083336d5fab7e7b19a3f8e1f0dad86644e708b18b926b9de3a678edf8b31495097e319bff970599b80d0ab21d9
@@ -0,0 +1,10 @@
1
+ # c.f. https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
2
+ version: 2
3
+
4
+ updates:
5
+ - package-ecosystem: github-actions
6
+ directory: /
7
+ schedule:
8
+ interval: weekly
9
+ assignees:
10
+ - sue445
@@ -0,0 +1,68 @@
1
+ # Simple workflow for deploying static content to GitHub Pages
2
+ name: Deploy static content to Pages
3
+
4
+ on:
5
+ # Runs on pushes targeting the default branch
6
+ push:
7
+ branches:
8
+ - main
9
+
10
+ # Allows you to run this workflow manually from the Actions tab
11
+ workflow_dispatch:
12
+
13
+ # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
14
+ permissions:
15
+ contents: read
16
+ pages: write
17
+ id-token: write
18
+
19
+ # Allow one concurrent deployment
20
+ concurrency:
21
+ group: "pages"
22
+ cancel-in-progress: true
23
+
24
+ jobs:
25
+ # Single deploy job since we're just deploying
26
+ deploy:
27
+ environment:
28
+ name: github-pages
29
+ url: ${{ steps.deployment.outputs.page_url }}
30
+ runs-on: ubuntu-latest
31
+ steps:
32
+ - name: Checkout
33
+ uses: actions/checkout@v4
34
+
35
+ - name: Install packages
36
+ run: |
37
+ set -xe
38
+ sudo apt-get update
39
+ sudo apt-get install -y libgda-5.0
40
+
41
+ - uses: ruby/setup-ruby@v1
42
+ with:
43
+ ruby-version: ruby
44
+ bundler-cache: true
45
+
46
+ - run: bundle exec yard
47
+
48
+ - name: Setup Pages
49
+ uses: actions/configure-pages@v3
50
+ - name: Upload artifact
51
+ uses: actions/upload-pages-artifact@v2
52
+ with:
53
+ # Upload entire repository
54
+ path: './doc'
55
+ - name: Deploy to GitHub Pages
56
+ id: deployment
57
+ uses: actions/deploy-pages@main
58
+
59
+ - name: Slack Notification (not success)
60
+ uses: lazy-actions/slatify@master
61
+ if: "! success()"
62
+ continue-on-error: true
63
+ with:
64
+ job_name: "*pages*"
65
+ type: ${{ job.status }}
66
+ icon_emoji: ":octocat:"
67
+ url: ${{ secrets.SLACK_WEBHOOK }}
68
+ token: ${{ secrets.GITHUB_TOKEN }}
@@ -21,23 +21,19 @@ jobs:
21
21
 
22
22
  matrix:
23
23
  ruby:
24
- - "2.6"
25
- - "2.7"
26
24
  - "3.0"
27
25
  - "3.1"
26
+ - "3.2"
28
27
  gemfile:
29
28
  - activerecord_6_1
30
29
  - activerecord_7_0
31
- exclude:
32
- # activerecord 7.0+ requires Ruby 2.7+
33
- - ruby: "2.6"
34
- gemfile: activerecord_7_0
30
+ - activerecord_7_1
35
31
 
36
32
  env:
37
33
  BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
38
34
 
39
35
  steps:
40
- - uses: actions/checkout@v2
36
+ - uses: actions/checkout@v4
41
37
 
42
38
  - name: Install packages
43
39
  run: |
data/.rubocop.yml CHANGED
@@ -1,10 +1,11 @@
1
1
  require:
2
2
  - rubocop-performance
3
+ - rubocop-yard
3
4
 
4
5
  AllCops:
5
6
  NewCops: enable
6
7
  SuggestExtensions: false
7
- TargetRubyVersion: 2.6
8
+ TargetRubyVersion: 3.0
8
9
  Exclude:
9
10
  - 'gemfiles/vendor/**/*'
10
11
  - 'benchmark/**/*'
@@ -15,6 +16,9 @@ AllCops:
15
16
  - 'vendor/**/*'
16
17
  - '.git/**/*'
17
18
 
19
+ Gemspec/DevelopmentDependencies:
20
+ EnforcedStyle: gemspec
21
+
18
22
  Layout/DotPosition:
19
23
  EnforcedStyle: trailing
20
24
 
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  ## [Unreleased]
2
- [full changelog](http://github.com/sue445/rubocop-isucon/compare/v0.2.0...main)
2
+ [full changelog](http://github.com/sue445/rubocop-isucon/compare/v1.0.0...main)
3
+
4
+ ## [1.0.0] - 2023-10-29
5
+ [full changelog](http://github.com/sue445/rubocop-isucon/compare/v0.2.0...v1.0.0)
6
+
7
+ * Requires Ruby 3.0+
8
+ * https://github.com/sue445/rubocop-isucon/pull/236
9
+
10
+ ## [0.2.0] - 2022-07-31
11
+ [full changelog](http://github.com/sue445/rubocop-isucon/compare/v0.1.0...v0.2.0)
3
12
 
4
13
  * Add `Isucon/Sqlite3/SelectAsterisk`
5
14
  * https://github.com/sue445/rubocop-isucon/pull/202
@@ -12,9 +21,6 @@
12
21
  * Add `Isucon/Sqlite3/NPlusOneQuery`
13
22
  * https://github.com/sue445/rubocop-isucon/pull/210
14
23
 
15
- ## [0.1.0] - 2022-07-31
16
- [full changelog](http://github.com/sue445/rubocop-isucon/compare/v0.1.0...v0.2.0)
17
-
18
24
  ## [0.1.0] - 2022-07-23
19
25
 
20
26
  - Initial release
data/README.md CHANGED
@@ -117,3 +117,10 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/sue445
117
117
  ## License
118
118
 
119
119
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
120
+
121
+ ISUCON is a trademark or registered trademark of LINE Corporation.
122
+
123
+ https://isucon.net
124
+
125
+ ## Presentation
126
+ * [Fix SQL N\+1 queries with RuboCop](https://speakerdeck.com/sue445/fix-sql-n-plus-one-queries-with-rubocop) at [RubyKaigi 2023](https://rubykaigi.org/2013/) :gem:
data/config/default.yml CHANGED
@@ -16,7 +16,7 @@ Isucon/Mysql2/ManyJoinTable:
16
16
  CountTables: 3
17
17
 
18
18
  Isucon/Mysql2/NPlusOneQuery:
19
- Description: 'Checks that N+1 query is not used'
19
+ Description: 'Checks that there’s no N+1 query'
20
20
  Enabled: true
21
21
  VersionAdded: '0.1.0'
22
22
  SafeAutoCorrect: false
@@ -100,7 +100,7 @@ Isucon/Sqlite3/ManyJoinTable:
100
100
  CountTables: 3
101
101
 
102
102
  Isucon/Sqlite3/NPlusOneQuery:
103
- Description: 'Checks that N+1 query is not used'
103
+ Description: 'Checks that there’s no N+1 query'
104
104
  Enabled: true
105
105
  VersionAdded: '0.2.0'
106
106
  SafeAutoCorrect: false
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 7.1.0"
6
+
7
+ group :sqlite3 do
8
+ # c.f. https://github.com/rails/rails/blob/v7.1.0/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb#L14
9
+ gem "sqlite3", "~> 1.4"
10
+ end
11
+
12
+ # eval_gemfile "#{__dir__}/common.gemfile"
13
+
14
+ gemspec path: "../"
@@ -9,7 +9,7 @@ module RuboCop
9
9
  module Correctors
10
10
  # rubocop:disable Layout/LineLength
11
11
 
12
- # Corrector for {RuboCop::Cop::Isucon::Mysql2::NPlusOneQuery}
12
+ # Corrector for {RuboCop::Cop::Isucon::Mysql2::NPlusOneQuery} and {RuboCop::Cop::Isucon::Sqlite3::NPlusOneQuery}
13
13
  #
14
14
  # @example Before
15
15
  # courses.map do |course|
@@ -62,7 +62,7 @@ module RuboCop
62
62
  end
63
63
 
64
64
  # @param select_field_node [GDA::Nodes::SelectField]
65
- # @return [Hash<Symbol, String>] table_name, column_name
65
+ # @return [Hash{Symbol => String}] table_name, column_name
66
66
  def parse_select_field_node(select_field_node)
67
67
  column_elements = select_field_node.expr.value.split(".", 2)
68
68
 
@@ -6,7 +6,7 @@ module RuboCop
6
6
  module Mysql2
7
7
  # rubocop:disable Layout/LineLength
8
8
 
9
- # Checks that N+1 query is not used
9
+ # Checks that there’s no N+1 query
10
10
  #
11
11
  # @note If `Database` isn't configured, auto-correct will not be available. (Only offense detection can be used)
12
12
  #
@@ -10,10 +10,10 @@ module RuboCop
10
10
  #
11
11
  # @example
12
12
  # # bad (user_id is not indexed)
13
- # db.xquery('SELECT id, title FROM articles WHERE used_id = ?', user_id)
13
+ # db.xquery('SELECT id, title FROM articles WHERE user_id = ?', user_id)
14
14
  #
15
15
  # # good (user_id is indexed)
16
- # db.xquery('SELECT id, title FROM articles WHERE used_id = ?', user_id)
16
+ # db.xquery('SELECT id, title FROM articles WHERE user_id = ?', user_id)
17
17
  #
18
18
  # # good (id is primary key)
19
19
  # db.xquery('SELECT id, title FROM articles WHERE id = ?', id)
@@ -22,6 +22,13 @@ module RuboCop
22
22
  # OpenSSL::Digest::SHA512.hexdigest(src)
23
23
  # end
24
24
  #
25
+ # # bad
26
+ # `curl -s https://example.com`
27
+ #
28
+ # # good
29
+ # require "open-uri"
30
+ # URI.open("https://example.com").read
31
+ #
25
32
  class Backtick < Base
26
33
  MSG = "Use pure-ruby code instead of external command execution if possible"
27
34
 
@@ -6,7 +6,7 @@ module RuboCop
6
6
  module Sqlite3
7
7
  # rubocop:disable Layout/LineLength
8
8
 
9
- # Checks that N+1 query is not used
9
+ # Checks that there’s no N+1 query
10
10
  #
11
11
  # @note If `Database` isn't configured, auto-correct will not be available. (Only offense detection can be used)
12
12
  #
@@ -10,10 +10,10 @@ module RuboCop
10
10
  #
11
11
  # @example
12
12
  # # bad (user_id is not indexed)
13
- # db.execute('SELECT id, title FROM articles WHERE used_id = ?', [user_id])
13
+ # db.execute('SELECT id, title FROM articles WHERE user_id = ?', [user_id])
14
14
  #
15
15
  # # good (user_id is indexed)
16
- # db.execute('SELECT id, title FROM articles WHERE used_id = ?', [user_id])
16
+ # db.execute('SELECT id, title FROM articles WHERE user_id = ?', [user_id])
17
17
  #
18
18
  # # good (id is primary key)
19
19
  # db.execute('SELECT id, title FROM articles WHERE id = ?', [id])
@@ -33,7 +33,7 @@ module RuboCop
33
33
 
34
34
  @table_names =
35
35
  if from_targets?
36
- ast.from.targets.map(&:table_name).compact.uniq
36
+ ast.from.targets.filter_map(&:table_name).uniq
37
37
  else
38
38
  []
39
39
  end
@@ -25,7 +25,7 @@ module RuboCop
25
25
  # @param column_name [String]
26
26
  # @param as [String]
27
27
  # @param node [GDA::Nodes::Expr]
28
- def initialize(table_name: nil, column_name: nil, as: nil, node: nil) # rubocop:disable Naming/MethodParameterName
28
+ def initialize(table_name: nil, column_name: nil, as: nil, node: nil)
29
29
  @table_name = table_name
30
30
  @column_name = column_name
31
31
  @as = as
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Isucon
5
- VERSION = "0.2.0"
5
+ VERSION = "1.0.0"
6
6
  end
7
7
  end
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
12
12
  spec.description = "RuboCop plugin for ruby reference implementation of ISUCON"
13
13
  spec.homepage = "https://github.com/sue445/rubocop-isucon"
14
14
  spec.license = "MIT"
15
- spec.required_ruby_version = ">= 2.6.0"
15
+ spec.required_ruby_version = ">= 3.0.0"
16
16
 
17
17
  spec.metadata["homepage_uri"] = spec.homepage
18
18
  spec.metadata["source_code_uri"] = "https://github.com/sue445/rubocop-isucon"
@@ -37,7 +37,7 @@ Gem::Specification.new do |spec|
37
37
 
38
38
  spec.add_runtime_dependency "activerecord", ">= 6.1.0"
39
39
  spec.add_runtime_dependency "gda", "!= 1.1.2"
40
- spec.add_runtime_dependency "rubocop", ">= 1.29.0"
40
+ spec.add_runtime_dependency "rubocop", ">= 1.49.0"
41
41
  spec.add_runtime_dependency "rubocop-performance"
42
42
 
43
43
  spec.add_development_dependency "benchmark-ips"
@@ -47,6 +47,7 @@ Gem::Specification.new do |spec|
47
47
  spec.add_development_dependency "rspec", "~> 3.0"
48
48
  spec.add_development_dependency "rspec-its"
49
49
  spec.add_development_dependency "rubocop_auto_corrector"
50
+ spec.add_development_dependency "rubocop-yard"
50
51
  spec.add_development_dependency "sqlite3"
51
52
  spec.add_development_dependency "yard"
52
53
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-isucon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - sue445
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-07-31 00:00:00.000000000 Z
11
+ date: 2023-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 1.29.0
47
+ version: 1.49.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 1.29.0
54
+ version: 1.49.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rubocop-performance
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -164,6 +164,20 @@ dependencies:
164
164
  - - ">="
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: rubocop-yard
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
167
181
  - !ruby/object:Gem::Dependency
168
182
  name: sqlite3
169
183
  requirement: !ruby/object:Gem::Requirement
@@ -199,7 +213,8 @@ executables: []
199
213
  extensions: []
200
214
  extra_rdoc_files: []
201
215
  files:
202
- - ".github/workflows/gh-pages.yml"
216
+ - ".github/dependabot.yml"
217
+ - ".github/workflows/pages.yml"
203
218
  - ".github/workflows/test.yml"
204
219
  - ".gitignore"
205
220
  - ".rspec"
@@ -220,6 +235,7 @@ files:
220
235
  - config/enable-only-performance.yml
221
236
  - gemfiles/activerecord_6_1.gemfile
222
237
  - gemfiles/activerecord_7_0.gemfile
238
+ - gemfiles/activerecord_7_1.gemfile
223
239
  - lib/rubocop-isucon.rb
224
240
  - lib/rubocop/cop/isucon/correctors/n_plus_one_query_corrector.rb
225
241
  - lib/rubocop/cop/isucon/correctors/n_plus_one_query_corrector/correctable_methods.rb
@@ -284,14 +300,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
284
300
  requirements:
285
301
  - - ">="
286
302
  - !ruby/object:Gem::Version
287
- version: 2.6.0
303
+ version: 3.0.0
288
304
  required_rubygems_version: !ruby/object:Gem::Requirement
289
305
  requirements:
290
306
  - - ">="
291
307
  - !ruby/object:Gem::Version
292
308
  version: '0'
293
309
  requirements: []
294
- rubygems_version: 3.3.7
310
+ rubygems_version: 3.4.10
295
311
  signing_key:
296
312
  specification_version: 4
297
313
  summary: RuboCop plugin for ruby reference implementation of ISUCON
@@ -1,44 +0,0 @@
1
- name: gh-pages
2
-
3
- on:
4
- push:
5
- branches:
6
- - main
7
-
8
- jobs:
9
- publish_yard:
10
- runs-on: ubuntu-latest
11
-
12
- steps:
13
- - uses: actions/checkout@v2
14
-
15
- - name: Install packages
16
- run: |
17
- set -xe
18
- sudo apt-get update
19
- sudo apt-get install -y libgda-5.0
20
-
21
- - uses: ruby/setup-ruby@v1
22
- with:
23
- ruby-version: "3.1"
24
- bundler-cache: true
25
-
26
- - run: bundle exec yard
27
-
28
- - name: Deploy to GitHub Pages
29
- uses: peaceiris/actions-gh-pages@v3
30
- with:
31
- github_token: ${{ secrets.GITHUB_TOKEN }}
32
- publish_dir: ./doc
33
- publish_branch: gh-pages
34
-
35
- - name: Slack Notification (not success)
36
- uses: lazy-actions/slatify@master
37
- if: "! success()"
38
- continue-on-error: true
39
- with:
40
- job_name: ${{ format('*publish_yard*') }}
41
- type: ${{ job.status }}
42
- icon_emoji: ":octocat:"
43
- url: ${{ secrets.SLACK_WEBHOOK }}
44
- token: ${{ secrets.GITHUB_TOKEN }}