From f8515263f0f1fbbed4530811f38e7f0556489746 Mon Sep 17 00:00:00 2001 From: Alhassan Osman Date: Fri, 17 Nov 2023 10:06:11 +0000 Subject: [PATCH 1/5] Create linters.yml --- .github/workflows/linters.yml | 44 +++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 .github/workflows/linters.yml diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml new file mode 100644 index 0000000..4671d69 --- /dev/null +++ b/.github/workflows/linters.yml @@ -0,0 +1,44 @@ +name: Linters + +on: pull_request + +env: + FORCE_COLOR: 1 + +jobs: + rubocop: + name: Rubocop + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-ruby@v1 + with: + ruby-version: 3.1.x + - name: Setup Rubocop + run: | + gem install --no-document rubocop -v '>= 1.0, < 2.0' # https://docs.rubocop.org/en/stable/installation/ + [ -f .rubocop.yml ] || wget https://raw.githubusercontent.com/microverseinc/linters-config/master/ror/.rubocop.yml + - name: Rubocop Report + run: rubocop --color + stylelint: + name: Stylelint + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: "18.x" + - name: Setup Stylelint + run: | + npm install --save-dev stylelint@13.x stylelint-scss@3.x stylelint-config-standard@21.x stylelint-csstree-validator@1.x + [ -f .stylelintrc.json ] || wget https://raw.githubusercontent.com/microverseinc/linters-config/master/ror/.stylelintrc.json + - name: Stylelint Report + run: npx stylelint "**/*.{css,scss}" + nodechecker: + name: node_modules checker + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + - name: Check node_modules existence + run: | + if [ -d "node_modules/" ]; then echo -e "\e[1;31mThe node_modules/ folder was pushed to the repo. Please remove it from the GitHub repository and try again."; echo -e "\e[1;32mYou can set up a .gitignore file with this folder included on it to prevent this from happening in the future." && exit 1; fi \ No newline at end of file From 409c638c17eabbf7dba278ba8b1a6b091f4d0f4c Mon Sep 17 00:00:00 2001 From: Alhassan Osman Date: Fri, 17 Nov 2023 10:09:21 +0000 Subject: [PATCH 2/5] Add Rubocop to project --- Gemfile | 1 + Gemfile.lock | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/Gemfile b/Gemfile index ccf809d..16461ac 100644 --- a/Gemfile +++ b/Gemfile @@ -74,4 +74,5 @@ group :test do end gem 'devise' +gem 'rubocop', '>= 1.0', '< 2.0' gem 'tailwindcss-rails', '~> 2.0' diff --git a/Gemfile.lock b/Gemfile.lock index 7a5fd02..e7d8b88 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -68,6 +68,7 @@ GEM tzinfo (~> 2.0) addressable (2.8.5) public_suffix (>= 2.0.2, < 6.0) + ast (2.4.2) bcrypt (3.1.19) bindex (0.8.1) bootsnap (1.17.0) @@ -111,6 +112,8 @@ GEM jbuilder (2.11.5) actionview (>= 5.0.0) activesupport (>= 5.0.0) + json (2.6.3) + language_server-protocol (3.17.0.3) launchy (2.5.2) addressable (~> 2.8) letter_opener (1.8.1) @@ -144,6 +147,10 @@ GEM nokogiri (1.15.4-x86_64-linux) racc (~> 1.4) orm_adapter (0.5.0) + parallel (1.23.0) + parser (3.2.2.4) + ast (~> 2.4.1) + racc pg (1.5.4) psych (5.1.1.1) stringio @@ -182,6 +189,7 @@ GEM rake (>= 12.2) thor (~> 1.0) zeitwerk (~> 2.5) + rainbow (3.1.1) rake (13.1.0) rdoc (6.6.0) psych (>= 4.0.0) @@ -192,6 +200,20 @@ GEM actionpack (>= 5.2) railties (>= 5.2) rexml (3.2.6) + rubocop (1.57.2) + json (~> 2.3) + language_server-protocol (>= 3.17.0) + parallel (~> 1.10) + parser (>= 3.2.2.4) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.28.1, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.30.0) + parser (>= 3.2.1.0) + ruby-progressbar (1.13.0) rubyzip (2.3.2) selenium-webdriver (4.15.0) rexml (~> 3.2, >= 3.2.5) @@ -219,6 +241,7 @@ GEM railties (>= 6.0.0) tzinfo (2.0.6) concurrent-ruby (~> 1.0) + unicode-display_width (2.5.0) warden (1.2.9) rack (>= 2.0.9) web-console (4.2.1) @@ -250,6 +273,7 @@ DEPENDENCIES pg (~> 1.1) puma (~> 5.0) rails (~> 7.0.8) + rubocop (>= 1.0, < 2.0) selenium-webdriver sprockets-rails stimulus-rails From f38c592905e7f93328f0b204dbdd7a814960b9c0 Mon Sep 17 00:00:00 2001 From: Alhassan Osman Date: Fri, 17 Nov 2023 10:09:38 +0000 Subject: [PATCH 3/5] Fix rubocop errrors --- app/models/food.rb | 20 ++++++++++---------- app/models/user.rb | 20 ++++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/app/models/food.rb b/app/models/food.rb index fe427fe..1deac7e 100644 --- a/app/models/food.rb +++ b/app/models/food.rb @@ -1,10 +1,10 @@ -class Food < ApplicationRecord - belongs_to :user - has_many :recipe_foods, dependent: :destroy - - validates :name, presence: true, length: { maximum: 250, too_long: '%s characters is the maximum allowed' } - validates :measurement_unit, presence: true, - length: { maximum: 50, too_long: '%s characters is the maximum allowed' } - validates :price, presence: true, numericality: { greater_than_or_equal_to: 0 } - validates :quantity, presence: true -end +class Food < ApplicationRecord + belongs_to :user + has_many :recipe_foods, dependent: :destroy + + validates :name, presence: true, length: { maximum: 250, too_long: '%s characters is the maximum allowed' } + validates :measurement_unit, presence: true, + length: { maximum: 50, too_long: '%s characters is the maximum allowed' } + validates :price, presence: true, numericality: { greater_than_or_equal_to: 0 } + validates :quantity, presence: true +end diff --git a/app/models/user.rb b/app/models/user.rb index 5da774c..acae5f7 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,10 +1,10 @@ -class User < ApplicationRecord - # Include default devise modules. Others available are: - # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable - devise :database_authenticatable, :registerable, - :recoverable, :rememberable, :validatable, :confirmable - has_many :foods, dependent: :destroy - has_many :recipes, dependent: :destroy - - validates :name, presence: true, length: { maximum: 250, too_long: '%s characters is the maximum allowed' } -end +class User < ApplicationRecord + # Include default devise modules. Others available are: + # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable + devise :database_authenticatable, :registerable, + :recoverable, :rememberable, :validatable, :confirmable + has_many :foods, dependent: :destroy + has_many :recipes, dependent: :destroy + + validates :name, presence: true, length: { maximum: 250, too_long: '%s characters is the maximum allowed' } +end From dde2ebc2da906c5404afa6a82b948c308410f38d Mon Sep 17 00:00:00 2001 From: Alhassan Osman Date: Fri, 17 Nov 2023 10:12:42 +0000 Subject: [PATCH 4/5] Create .stylelintrc.json --- .stylelintrc.json | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 .stylelintrc.json diff --git a/.stylelintrc.json b/.stylelintrc.json new file mode 100644 index 0000000..7a1e94b --- /dev/null +++ b/.stylelintrc.json @@ -0,0 +1,32 @@ +{ + "extends": ["stylelint-config-standard"], + "plugins": ["stylelint-scss", "stylelint-csstree-validator"], + "rules": { + "at-rule-no-unknown": [ + true, + { + "ignoreAtRules": [ + "tailwind", + "apply", + "variants", + "responsive", + "screen" + ] + } + ], + "scss/at-rule-no-unknown": [ + true, + { + "ignoreAtRules": [ + "tailwind", + "apply", + "variants", + "responsive", + "screen" + ] + } + ], + "csstree/validator": true + }, + "ignoreFiles": ["build/**", "dist/**", "**/reset*.css", "**/bootstrap*.css"] +} From 9945f817a1ed7ba600a64c7ecc4217c943509482 Mon Sep 17 00:00:00 2001 From: Alhassan Osman Date: Fri, 17 Nov 2023 10:13:05 +0000 Subject: [PATCH 5/5] Fix Stylelint errors --- app/assets/stylesheets/application.tailwind.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/stylesheets/application.tailwind.css b/app/assets/stylesheets/application.tailwind.css index fdad3af..5c78838 100644 --- a/app/assets/stylesheets/application.tailwind.css +++ b/app/assets/stylesheets/application.tailwind.css @@ -8,4 +8,4 @@ @apply py-2 px-4 bg-blue-200; } } -*/ \ No newline at end of file +*/