Skip to content

Commit 4566106

Browse files
committed
Use StandardRB for linting & formatting
Simple, minimal config, effective Fixes #101
1 parent 02d6bfc commit 4566106

24 files changed

+540
-515
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,7 @@ jobs:
1818
with:
1919
ruby-version: ${{ matrix.ruby-version }}
2020
bundler-cache: true
21+
- name: Run StandardRB
22+
run: bundle exec rake standard
2123
- name: Run test suite
2224
run: bundle exec rake

.rubocop.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.

CONTRIBUTING.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,28 @@ For fixes and small additions, follow the steps below to get developing and cont
88
2. Run the `bin/setup` script to install development dependencies
99
3. Work on a branch
1010
4. Make changes
11-
5. Ensure tests pass by running `bin/rake`
11+
5. Ensure tests and code style checks pass by running `bin/rake` (runs both StandardRB and tests)
1212
6. Commit your changes, this project follows [the Conventional Commits spec](https://www.conventionalcommits.org/en/v1.0.0/)
1313
7. Open up a pull request
1414

15+
## Code Style
16+
17+
This project uses [StandardRB](https://github.com/standardrb/standard) for Ruby code style. StandardRB is an opinionated, zero-configuration linter and formatter.
18+
19+
Before committing your changes, make sure your code passes StandardRB:
20+
21+
```console
22+
bundle exec rake standard
23+
```
24+
25+
To automatically fix most style issues:
26+
27+
```console
28+
bundle exec rake standard:fix
29+
```
30+
31+
The default `bin/rake` command runs both StandardRB checks and the test suite, so you can verify everything at once.
32+
1533
## Finding Issues
1634

1735
- Good First Issue — If you're new to the project or Ruby, check out the ["good first issue" tag](https://github.com/brettchalupa/graphql-docs/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22). They're smaller, approachable issues if you're just getting started.

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
source 'https://rubygems.org'
3+
source "https://rubygems.org"
44

55
# Specify your gem's dependencies in graphql-docs.gemspec
66
gemspec

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,30 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
498498
`bin/rake test` to run the tests. You can also run `bin/console` for
499499
an interactive prompt that will allow you to experiment.
500500

501+
### Code Style
502+
503+
This project uses [StandardRB](https://github.com/standardrb/standard) for Ruby code style enforcement. StandardRB is a zero-configuration formatter and linter based on RuboCop.
504+
505+
To check your code style:
506+
507+
```console
508+
bundle exec rake standard
509+
```
510+
511+
To automatically fix style issues:
512+
513+
```console
514+
bundle exec rake standard:fix
515+
```
516+
517+
The default rake task runs both StandardRB and the test suite:
518+
519+
```console
520+
bundle exec rake
521+
```
522+
523+
StandardRB checks are also run in CI, so make sure your code passes before opening a pull request.
524+
501525
### Releasing a new version of the gem
502526

503527
1. Update CHANGELOG.md

Rakefile

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,114 @@
11
# frozen_string_literal: true
22

3-
require 'bundler/gem_tasks'
4-
require 'rake/testtask'
3+
require "bundler/gem_tasks"
4+
require "rake/testtask"
55

6-
require 'rubocop/rake_task'
7-
8-
RuboCop::RakeTask.new(:rubocop)
6+
require "standard/rake"
97

108
Rake::TestTask.new(:test) do |t|
11-
t.libs << 'test'
12-
t.libs << 'lib'
9+
t.libs << "test"
10+
t.libs << "lib"
1311
t.warning = false
14-
t.test_files = FileList['test/**/*_test.rb']
12+
t.test_files = FileList["test/**/*_test.rb"]
1513
end
1614

17-
task default: :test
15+
task default: [:standard, :test]
1816

19-
desc 'Invoke HTML-Proofer'
17+
desc "Invoke HTML-Proofer"
2018
task :html_proofer do
2119
Rake::Task[:generate_sample]
22-
require 'html-proofer'
23-
output_dir = File.join(File.dirname(__FILE__), 'output')
20+
require "html-proofer"
21+
output_dir = File.join(File.dirname(__FILE__), "output")
2422

25-
proofer_options = { disable_external: true, assume_extension: true }
23+
proofer_options = {disable_external: true, assume_extension: true}
2624
HTMLProofer.check_directory(output_dir, proofer_options).run
2725
end
2826

29-
desc 'Set up a console'
27+
desc "Set up a console"
3028
task :console do
31-
require 'graphql-docs'
29+
require "graphql-docs"
3230

3331
def reload!
3432
files = $LOADED_FEATURES.select { |feat| feat =~ %r{/graphql-docs/} }
3533
files.each { |file| load file }
3634
end
3735

38-
require 'irb'
36+
require "irb"
3937
ARGV.clear
4038
IRB.start
4139
end
4240

4341
namespace :yard do
44-
desc 'Generate YARD documentation'
42+
desc "Generate YARD documentation"
4543
task :doc do
46-
sh 'bundle exec yard doc'
44+
sh "bundle exec yard doc"
4745
end
4846

49-
desc 'Run YARD documentation server'
47+
desc "Run YARD documentation server"
5048
task :server do
5149
puts "Starting YARD server at http://localhost:8808"
5250
puts "Press Ctrl+C to stop"
53-
sh 'bundle exec yard server --reload --bind 0.0.0.0 --port 8808'
51+
sh "bundle exec yard server --reload --bind 0.0.0.0 --port 8808"
5452
end
5553
end
5654

5755
# Alias for convenience
58-
desc 'Generate YARD documentation'
59-
task yard: 'yard:doc'
56+
desc "Generate YARD documentation"
57+
task yard: "yard:doc"
6058

6159
namespace :sample do
62-
desc 'Generate the sample documentation'
60+
desc "Generate the sample documentation"
6361
task :generate do
64-
require 'graphql-docs'
62+
require "graphql-docs"
6563

6664
options = {}
6765
options[:delete_output] = true
68-
options[:base_url] = ENV.fetch('GQL_DOCS_BASE_URL', '')
69-
options[:filename] = File.join(File.dirname(__FILE__), 'test', 'graphql-docs', 'fixtures', 'gh-schema.graphql')
66+
options[:base_url] = ENV.fetch("GQL_DOCS_BASE_URL", "")
67+
options[:filename] = File.join(File.dirname(__FILE__), "test", "graphql-docs", "fixtures", "gh-schema.graphql")
7068

7169
puts "Generating sample docs"
7270
GraphQLDocs.build(options)
7371
end
7472

75-
desc 'Generate the documentation and run a web server'
73+
desc "Generate the documentation and run a web server"
7674
task serve: [:generate] do
77-
require 'webrick'
78-
PORT = "5050"
79-
puts "Navigate to http://localhost:#{PORT} to view the sample docs"
80-
server = WEBrick::HTTPServer.new Port: PORT
81-
server.mount '/', WEBrick::HTTPServlet::FileHandler, 'output'
82-
trap('INT') { server.stop }
75+
require "webrick"
76+
port = "5050"
77+
puts "Navigate to http://localhost:#{port} to view the sample docs"
78+
server = WEBrick::HTTPServer.new Port: port
79+
server.mount "/", WEBrick::HTTPServlet::FileHandler, "output"
80+
trap("INT") { server.stop }
8381
server.start
8482
end
8583
task server: :serve
8684

87-
desc 'Run the sample docs as a Rack application (dynamic, on-demand generation)'
85+
desc "Run the sample docs as a Rack application (dynamic, on-demand generation)"
8886
task :rack do
89-
require 'rack'
90-
require 'graphql-docs'
87+
require "rack"
88+
require "graphql-docs"
9189

92-
schema_path = File.join(File.dirname(__FILE__), 'test', 'graphql-docs', 'fixtures', 'gh-schema.graphql')
90+
schema_path = File.join(File.dirname(__FILE__), "test", "graphql-docs", "fixtures", "gh-schema.graphql")
9391
schema = File.read(schema_path)
9492

95-
app = GraphQLDocs::App.new(
93+
GraphQLDocs::App.new(
9694
schema: schema,
9795
options: {
98-
base_url: '',
96+
base_url: "",
9997
use_default_styles: true,
10098
cache: true
10199
}
102100
)
103101

104-
PORT = ENV.fetch('PORT', '9292')
102+
port = ENV.fetch("PORT", "9292")
105103
puts "Starting Rack server in dynamic mode (on-demand generation)"
106-
puts "Navigate to http://localhost:#{PORT} to view the sample docs"
104+
puts "Navigate to http://localhost:#{port} to view the sample docs"
107105
puts "Press Ctrl+C to stop"
108106
puts ""
109107
puts "NOTE: This serves documentation dynamically - pages are generated on request"
110108
puts " Compare with 'rake sample:serve' which serves pre-generated static files"
111109
puts ""
112110

113111
# Use rackup for Rack 3.x compatibility
114-
sh "rackup config.ru -p #{PORT}"
112+
sh "rackup config.ru -p #{port}"
115113
end
116114
end

config.ru

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
# Run with: rackup config.ru
99
# Or with specific port: rackup config.ru -p 9292
1010

11-
require_relative 'lib/graphql-docs'
11+
require_relative "lib/graphql-docs"
1212

1313
# Load the sample GraphQL schema
14-
schema_path = File.join(__dir__, 'test', 'graphql-docs', 'fixtures', 'gh-schema.graphql')
14+
schema_path = File.join(__dir__, "test", "graphql-docs", "fixtures", "gh-schema.graphql")
1515

1616
unless File.exist?(schema_path)
1717
puts "Error: Sample schema not found at #{schema_path}"
@@ -25,7 +25,7 @@ schema = File.read(schema_path)
2525
app = GraphQLDocs::App.new(
2626
schema: schema,
2727
options: {
28-
base_url: '',
28+
base_url: "",
2929
use_default_styles: true,
3030
cache: true
3131
}
@@ -35,7 +35,7 @@ app = GraphQLDocs::App.new(
3535
use Rack::CommonLogger
3636

3737
# Add reloader for development (optional, requires 'rack' gem)
38-
if ENV['RACK_ENV'] != 'production'
38+
if ENV["RACK_ENV"] != "production"
3939
puts "Running in development mode"
4040
puts "Visit http://localhost:9292 to view the documentation"
4141
puts "Press Ctrl+C to stop the server"

exe/graphql-docs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ OptionParser.new do |parser|
1010
parser.program_name = NAME
1111
parser.banner = <<~EOS
1212
13-
Generate GraphQL docs from the passed in schema file.
13+
Generate GraphQL docs from the passed in schema file.
1414
15-
Usage: graphql-docs SCHEMA
15+
Usage: graphql-docs SCHEMA
1616
17-
The only required argument is the path to the schema file to generate the site from.
17+
The only required argument is the path to the schema file to generate the site from.
1818
19-
Examples:
20-
$ graphql-docs schema.graphql
21-
$ graphql-docs schema.graphql -o _docs
19+
Examples:
20+
$ graphql-docs schema.graphql
21+
$ graphql-docs schema.graphql -o _docs
2222
23-
Options:
23+
Options:
2424
EOS
2525

2626
parser.version = GraphQLDocs::VERSION
@@ -51,7 +51,7 @@ verbose = opts.delete(:verbose)
5151

5252
puts("Generating site with the following options: #{opts}") if verbose
5353

54-
opts.transform_keys! { |k| k.to_s.gsub("-", "_").to_sym }
54+
opts.transform_keys! { |k| k.to_s.tr("-", "_").to_sym }
5555
GraphQLDocs.build(opts)
5656

57-
puts("Site successfully generated in: #{opts[:output_dir] || 'output' }") if verbose
57+
puts("Site successfully generated in: #{opts[:output_dir] || "output"}") if verbose

0 commit comments

Comments
 (0)