diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..7abff8a --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,283 @@ +# https://evilmartians.com/chronicles/rubocoping-with-legacy-bring-your-ruby-code-up-to-standard +inherit_mode: + merge: + - Exclude + +inherit_from: + - .rubocop/rails.yml + - .rubocop_todo.yml + - .rubocop/strict.yml + # - .rubocop/rspec.yml + # - node_modules/@prettier/plugin-ruby/rubocop.yml + +require: + - rubocop-performance + - rubocop-rake + # - rubocop-minitest + +AllCops: + TargetRubyVersion: 3.2 + TargetRailsVersion: 7.0 + SuggestExtensions: false + # RuboCop has a bunch of cops enabled by default. This setting tells RuboCop + # to ignore them, so only the ones explicitly set in this file are enabled. + DisabledByDefault: true + Exclude: + - 'db/**/*' + - 'config/**/*' + - 'script/**/*' + - '**/Gemfile.lock' + - '**/Rakefile' + - '**/rails' + - '**/vendor/**/*' + - '**/spec_helper.rb' + - 'node_modules/**/*' + - 'bin/*' + - !ruby/regexp /old_and_unused\.rb$/ + +Layout/LineLength: + Max: 300 + AllowedPatterns: + - !ruby/regexp /\A#/ + +# Prefer &&/|| over and/or. +Style/AndOr: + Enabled: true + +# Align `when` with `case`. +Layout/CaseIndentation: + Enabled: true + +Layout/ClosingHeredocIndentation: + Enabled: true + +Layout/ClosingParenthesisIndentation: + Enabled: true + +# Align comments with method definitions. +Layout/CommentIndentation: + Enabled: true + +Layout/ElseAlignment: + Enabled: true + +# Align `end` with the matching keyword or starting expression except for +# assignments, where it should be aligned with the LHS. +Layout/EndAlignment: + Enabled: true + EnforcedStyleAlignWith: variable + AutoCorrect: true + +Layout/EndOfLine: + Enabled: true + +Layout/EmptyLineAfterMagicComment: + Enabled: true + +Layout/EmptyLinesAroundAccessModifier: + Enabled: true + EnforcedStyle: only_before + +Layout/EmptyLinesAroundBlockBody: + Enabled: true + +# In a regular class definition, no empty lines around the body. +Layout/EmptyLinesAroundClassBody: + Enabled: true + +# In a regular method definition, no empty lines around the body. +Layout/EmptyLinesAroundMethodBody: + Enabled: true + +# In a regular module definition, no empty lines around the body. +Layout/EmptyLinesAroundModuleBody: + Enabled: true + +# Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }. +Style/HashSyntax: + Enabled: true + +# Method definitions after `private` or `protected` isolated calls need one +# extra level of indentation. +Layout/IndentationConsistency: + Enabled: true + EnforcedStyle: indented_internal_methods + Exclude: + - '**/*.md' + +# Two spaces, no tabs (for indentation). +Layout/IndentationWidth: + Enabled: true + +Layout/LeadingCommentSpace: + Enabled: true + +Layout/SpaceAfterColon: + Enabled: true + +Layout/SpaceAfterComma: + Enabled: true + +Layout/SpaceAfterSemicolon: + Enabled: true + +Layout/SpaceAroundEqualsInParameterDefault: + Enabled: true + +Layout/SpaceAroundKeyword: + Enabled: true + +Layout/SpaceAroundOperators: + Enabled: true + +Layout/SpaceBeforeComma: + Enabled: true + +Layout/SpaceBeforeComment: + Enabled: true + +Layout/SpaceBeforeFirstArg: + Enabled: true + +Style/DefWithParentheses: + Enabled: true + +# Defining a method with parameters needs parentheses. +Style/MethodDefParentheses: + Enabled: true + +Style/ExplicitBlockArgument: + Enabled: true + +Style/FrozenStringLiteralComment: + Enabled: true + EnforcedStyle: never + # Exclude: + # - 'actionview/test/**/*.builder' + # - 'actionview/test/**/*.ruby' + # - 'actionpack/test/**/*.builder' + # - 'actionpack/test/**/*.ruby' + # - 'activestorage/db/migrate/**/*.rb' + # - 'activestorage/db/update_migrate/**/*.rb' + # - 'actionmailbox/db/migrate/**/*.rb' + # - 'actiontext/db/migrate/**/*.rb' + # - '**/*.md' + +Style/MapToHash: + Enabled: true + +Style/RedundantFreeze: + Enabled: true + +# Use `foo {}` not `foo{}`. +Layout/SpaceBeforeBlockBraces: + Enabled: true + +# Use `foo { bar }` not `foo {bar}`. +Layout/SpaceInsideBlockBraces: + Enabled: true + EnforcedStyleForEmptyBraces: space + +# Use `{ a: 1 }` not `{a:1}`. +Layout/SpaceInsideHashLiteralBraces: + Enabled: true + +Layout/SpaceInsideParens: + Enabled: true + +# Check quotes usage according to lint rule below. +Style/StringLiterals: + Enabled: true + EnforcedStyle: double_quotes + +# Detect hard tabs, no hard tabs. +Layout/IndentationStyle: + Enabled: true + +# Empty lines should not have any spaces. +Layout/TrailingEmptyLines: + Enabled: true + +# No trailing whitespace. +Layout/TrailingWhitespace: + Enabled: true + +# Use quotes for string literals when they are enough. +Style/RedundantPercentQ: + Enabled: true + +Lint/AmbiguousOperator: + Enabled: true + +Lint/AmbiguousRegexpLiteral: + Enabled: true + +Lint/DuplicateRequire: + Enabled: true + +Lint/DuplicateMagicComment: + Enabled: true + +Lint/DuplicateMethods: + Enabled: true + +Lint/ErbNewArguments: + Enabled: true + +Lint/EnsureReturn: + Enabled: true + +# Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg. +Lint/RequireParentheses: + Enabled: true + +Lint/RedundantStringCoercion: + Enabled: true + +Lint/UriEscapeUnescape: + Enabled: true + +Lint/UselessAssignment: + Enabled: true + +Lint/DeprecatedClassMethods: + Enabled: true + +Style/EvalWithLocation: + Enabled: true + Exclude: + - '**/test/**/*' + +Style/ParenthesesAroundCondition: + Enabled: true + +Style/HashTransformKeys: + Enabled: true + +Style/HashTransformValues: + Enabled: true + +Style/RedundantBegin: + Enabled: true + +Style/RedundantReturn: + Enabled: true + AllowMultipleReturnValues: true + +Style/RedundantRegexpEscape: + Enabled: true + +Style/Semicolon: + Enabled: true + AllowAsExpressionSeparator: true + +# Prefer Foo.method over Foo::method +Style/ColonMethodCall: + Enabled: true + +Style/TrivialAccessors: + Enabled: true + +# Prefer a = b || c over a = b ? b : c +Style/RedundantCondition: + Enabled: true diff --git a/.rubocop/markdown.yml b/.rubocop/markdown.yml new file mode 100644 index 0000000..964e188 --- /dev/null +++ b/.rubocop/markdown.yml @@ -0,0 +1,5 @@ +Markdown: + # Whether to run RuboCop against non-valid snippets + WarnInvalid: false + # Whether to lint codeblocks without code attributes + Autodetect: false diff --git a/.rubocop/minitest.yml b/.rubocop/minitest.yml new file mode 100644 index 0000000..efc4715 --- /dev/null +++ b/.rubocop/minitest.yml @@ -0,0 +1,11 @@ +Minitest/AssertRaisesWithRegexpArgument: + Enabled: true + +Minitest/AssertWithExpectedArgument: + Enabled: true + +Minitest/SkipEnsure: + Enabled: true + +Minitest/UnreachableAssertion: + Enabled: true diff --git a/.rubocop/rails.yml b/.rubocop/rails.yml new file mode 100644 index 0000000..534bc7b --- /dev/null +++ b/.rubocop/rails.yml @@ -0,0 +1,197 @@ +# https://evilmartians.com/chronicles/rubocoping-with-legacy-bring-your-ruby-code-up-to-standard +# https://gist.github.com/palkan/24869b835c45e89116b9727b534e579e +require: + - rubocop-rails + +Rails/ActionFilter: + Enabled: true + EnforcedStyle: action + Include: + - app/controllers/**/*.rb + +Rails/ActiveRecordAliases: + Enabled: true + +Rails/ActiveSupportAliases: + Enabled: true + +Rails/ApplicationJob: + Enabled: true + +Rails/ApplicationRecord: + Enabled: true + +Rails/AssertNot: + Enabled: true + Include: + - '**/test/**/*' + +Rails/Blank: + Enabled: true + # Convert usages of `nil? || empty?` to `blank?` + NilOrEmpty: true + # Convert usages of `!present?` to `blank?` + NotPresent: true + # Convert usages of `unless present?` to `if blank?` + UnlessPresent: true + +Rails/BulkChangeTable: + Enabled: true + Database: null + Include: + - db/migrate/*.rb + +Rails/CreateTableWithTimestamps: + Enabled: true + Include: + - db/migrate/*.rb + +Rails/Date: + Enabled: true + EnforcedStyle: flexible + +Rails/Delegate: + Enabled: true + EnforceForPrefixed: true + +Rails/DelegateAllowBlank: + Enabled: true + +Rails/DynamicFindBy: + Enabled: true + Whitelist: + - find_by_sql + +Rails/EnumUniqueness: + Enabled: true + Include: + - app/models/**/*.rb + +Rails/EnvironmentComparison: + Enabled: true + +Rails/Exit: + Enabled: true + Include: + - app/**/*.rb + - config/**/*.rb + - lib/**/*.rb + Exclude: + - lib/**/*.rake + +Rails/FilePath: + Enabled: true + EnforcedStyle: arguments + +Rails/FindBy: + Enabled: true + Include: + - app/models/**/*.rb + +Rails/FindEach: + Enabled: true + Include: + - app/models/**/*.rb + +Rails/HasAndBelongsToMany: + Enabled: true + Include: + - app/models/**/*.rb + +Rails/HttpPositionalArguments: + Enabled: true + Include: + - 'spec/**/*' + - 'test/**/*' + +Rails/HttpStatus: + Enabled: true + EnforcedStyle: symbolic + +Rails/InverseOf: + Enabled: true + Include: + - app/models/**/*.rb + +Rails/LexicallyScopedActionFilter: + Enabled: true + Safe: false + Include: + - app/controllers/**/*.rb + +Rails/NotNullColumn: + Enabled: true + Include: + - db/migrate/*.rb + +Rails/Output: + Enabled: true + Include: + - app/**/*.rb + - config/**/*.rb + - db/**/*.rb + - lib/**/*.rb + +Rails/OutputSafety: + Enabled: true + +Rails/PluralizationGrammar: + Enabled: true + +Rails/Presence: + Enabled: true + +Rails/Present: + Enabled: true + NotNilAndNotEmpty: true + NotBlank: true + UnlessBlank: true + +Rails/ReadWriteAttribute: + Enabled: true + Include: + - app/models/**/*.rb + +Rails/RedundantReceiverInWithOptions: + Enabled: true + +Rails/RefuteMethods: + Enabled: true + Include: + - '**/test/**/*' + +Rails/RelativeDateConstant: + Enabled: true + AutoCorrect: false + +Rails/RequestReferer: + Enabled: true + EnforcedStyle: referer + +Rails/ReversibleMigration: + Enabled: true + Include: + - db/migrate/*.rb + +Rails/SafeNavigation: + Enabled: true + ConvertTry: false + +Rails/ScopeArgs: + Enabled: true + Include: + - app/models/**/*.rb + +Rails/TimeZone: + Enabled: true + EnforcedStyle: flexible + +Rails/UniqBeforePluck: + Enabled: true + EnforcedStyle: conservative + AutoCorrect: false + +Rails/Validation: + Enabled: true + Include: + - app/models/**/*.rb diff --git a/.rubocop/rspec.yml b/.rubocop/rspec.yml new file mode 100644 index 0000000..7f22ce2 --- /dev/null +++ b/.rubocop/rspec.yml @@ -0,0 +1,55 @@ +require: + - rubocop-rspec + +# Disable all cops by default, +# only enable those defined explcitly in this configuration file +RSpec: + Enabled: false + +RSpec/Focus: + Enabled: true + +RSpec/EmptyExampleGroup: + Enabled: true + +RSpec/EmptyLineAfterExampleGroup: + Enabled: true + +RSpec/EmptyLineAfterFinalLet: + Enabled: true + +RSpec/EmptyLineAfterHook: + Enabled: true + +RSpec/EmptyLineAfterSubject: + Enabled: true + +RSpec/HookArgument: + Enabled: true + +RSpec/HooksBeforeExamples: + Enabled: true + +RSpec/ImplicitExpect: + Enabled: true + +RSpec/IteratedExpectation: + Enabled: true + +RSpec/LetBeforeExamples: + Enabled: true + +RSpec/MissingExampleGroupArgument: + Enabled: true + +RSpec/ReceiveCounts: + Enabled: true + +RSpec/Capybara/CurrentPathExpectation: + Enabled: true + +RSpec/FactoryBot/AttributeDefinedStatically: + Enabled: true + +RSpec/FactoryBot/CreateList: + Enabled: true diff --git a/.rubocop/strict.yml b/.rubocop/strict.yml new file mode 100644 index 0000000..81a4724 --- /dev/null +++ b/.rubocop/strict.yml @@ -0,0 +1,19 @@ +Lint/Debugger: # don't leave binding.pry or debugger + Enabled: true + Exclude: [] + +# RSpec/Focus: # run ALL tests on CI +# Enabled: true +# Exclude: [] + +Rails/Output: # Don't leave puts-debugging + Enabled: true + Exclude: [] + +Rails/FindEach: # each could severely affect the performance, use find_each + Enabled: true + Exclude: [] + +Rails/UniqBeforePluck: # uniq.pluck and not pluck.uniq + Enabled: true + Exclude: [] diff --git a/.solargraph.yml b/.solargraph.yml new file mode 100644 index 0000000..3d84104 --- /dev/null +++ b/.solargraph.yml @@ -0,0 +1,33 @@ +--- +include: +- "**/*.rb" +- "./lib/**/*.rb" +exclude: +- spec/**/* +- test/**/* +- vendor/**/* +- ".bundle/**/*" +require: +- actioncable +- actionmailer +- actionpack +- actionview +- activejob +- activemodel +- activerecord +- activestorage +- activesupport +domains: [] +reporters: +- typecheck:strict +# - rubocop +# - require_not_found +formatter: + rubocop: + cops: safe + except: [] + only: [] + extra_args: [] +require_paths: [] +plugins: [] +max_files: 5000 diff --git a/.yardopts b/.yardopts new file mode 100644 index 0000000..a632ee2 --- /dev/null +++ b/.yardopts @@ -0,0 +1,8 @@ +--protected +--private +--embed-mixins +--debug +--markup=markdown +--readme=README.md +--title='Rails Fields - Ruby API Documentation' +'lib/**/*.rb' - '*.md' \ No newline at end of file diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..20836f2 --- /dev/null +++ b/Gemfile @@ -0,0 +1,21 @@ +# frozen_string_literal: true +source "https://rubygems.org" + +group :development, :test do + gem "yard" + gem "rubocop", require: false + gem "rubocop-performance", require: false + gem "rubocop-rails", require: false + gem "rubocop-rake", require: false + # gem 'rubocop-minitest', require: false + + gem "solargraph" + gem "debug", platforms: %i[mri windows] +end + +# gem "solargraph-rails", "~> 1.1.0" + +# gem "graphql" +# gem "graphiql-rails", group: :development + +# gem "formtastic", "~> 4.0" diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..220c4b6 --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ +yard: + bundle exec yard doc --protected --private --embed-mixins --debug lib/**/*.rb + +start-debug: + rdbg --nonstop --open -c -- bin/rails server -p 3050 + +rubocop-generate: + bundle exec rubocop \ + --auto-gen-config \ + --auto-gen-only-exclude \ + --no-exclude-limit