A platform for community discussion. Free, open, simple.
DEV: fix linter and linting config (#36815)
Sambb8ed7d6f98f
diff --git a/bin/annotaterb b/bin/annotaterbindex e6adc886e06..3152f2f83bf 100755--- a/bin/annotaterb+++ b/bin/annotaterb@@ -16,8 +16,10 @@ if File.file?(bundle_binstub)if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")load(bundle_binstub)else- abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.-Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")+ abort(+ "Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.+Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.",+ )endenddiff --git a/bin/bundle b/bin/bundleindex 27a9357d17e..d5219340e7c 100755--- a/bin/bundle+++ b/bin/bundle@@ -10,105 +10,107 @@require "rubygems"-m = Module.new do- module_function+m =+ Module.new do+ module_function- def invoked_as_script?- File.expand_path($0) == File.expand_path(__FILE__)- end+ def invoked_as_script?+ File.expand_path($0) == File.expand_path(__FILE__)+ end- def env_var_version- ENV["BUNDLER_VERSION"]- end+ def env_var_version+ ENV["BUNDLER_VERSION"]+ end- def cli_arg_version- return unless invoked_as_script? # don't want to hijack other binstubs- return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`- bundler_version = nil- update_index = nil- ARGV.each_with_index do |a, i|- if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN- bundler_version = a+ def cli_arg_version+ return unless invoked_as_script? # don't want to hijack other binstubs+ return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`+ bundler_version = nil+ update_index = nil+ ARGV.each_with_index do |a, i|+ if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN+ bundler_version = a+ end+ next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/+ bundler_version = $1+ update_index = iend- next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/- bundler_version = $1- update_index = i+ bundler_versionend- bundler_version- end-- def gemfile- gemfile = ENV["BUNDLE_GEMFILE"]- return gemfile if gemfile && !gemfile.empty?- File.expand_path("../../Gemfile", __FILE__)- end+ def gemfile+ gemfile = ENV["BUNDLE_GEMFILE"]+ return gemfile if gemfile && !gemfile.empty?- def lockfile- lockfile =- case File.basename(gemfile)- when "gems.rb" then gemfile.sub(/\.rb$/, gemfile)- else "#{gemfile}.lock"- end- File.expand_path(lockfile)- end+ File.expand_path("../../Gemfile", __FILE__)+ end- def lockfile_version- return unless File.file?(lockfile)- lockfile_contents = File.read(lockfile)- return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/- Regexp.last_match(1)- end+ def lockfile+ lockfile =+ case File.basename(gemfile)+ when "gems.rb"+ gemfile.sub(/\.rb$/, gemfile)+ else+ "#{gemfile}.lock"+ end+ File.expand_path(lockfile)+ end- def bundler_version- @bundler_version ||=- env_var_version || cli_arg_version ||- lockfile_version- end+ def lockfile_version+ return unless File.file?(lockfile)+ lockfile_contents = File.read(lockfile)+ unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/+ return+ end+ Regexp.last_match(1)+ end- def bundler_requirement- return "#{Gem::Requirement.default}.a" unless bundler_version+ def bundler_version+ @bundler_version ||= env_var_version || cli_arg_version || lockfile_version+ end- bundler_gem_version = Gem::Version.new(bundler_version)+ def bundler_requirement+ return "#{Gem::Requirement.default}.a" unless bundler_version- requirement = bundler_gem_version.approximate_recommendation+ bundler_gem_version = Gem::Version.new(bundler_version)- return requirement if Gem::Version.new(Gem::VERSION) >= Gem::Version.new("2.7.0")+ requirement = bundler_gem_version.approximate_recommendation- requirement += ".a" if bundler_gem_version.prerelease?+ return requirement if Gem::Version.new(Gem::VERSION) >= Gem::Version.new("2.7.0")- requirement- end+ requirement += ".a" if bundler_gem_version.prerelease?- def load_bundler!- ENV["BUNDLE_GEMFILE"] ||= gemfile+ requirement+ end- activate_bundler- end+ def load_bundler!+ ENV["BUNDLE_GEMFILE"] ||= gemfile- def activate_bundler- gem_error = activation_error_handling do- gem "bundler", bundler_requirement+ activate_bundlerend- return if gem_error.nil?- require_error = activation_error_handling do- require "bundler/version"++ def activate_bundler+ gem_error = activation_error_handling { gem "bundler", bundler_requirement }+ return if gem_error.nil?+ require_error = activation_error_handling { require "bundler/version" }+ if require_error.nil? &&+ Gem::Requirement.new(bundler_requirement).satisfied_by?(+ Gem::Version.new(Bundler::VERSION),+ )+ return+ end+ warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`"+ exit 42end- return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))- warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`"- exit 42- end- def activation_error_handling- yield- nil- rescue StandardError, LoadError => e- e+ def activation_error_handling+ yield+ nil+ rescue StandardError, LoadError => e+ e+ endend-endm.load_bundler!-if m.invoked_as_script?- load Gem.bin_path("bundler", "bundle")-end+load Gem.bin_path("bundler", "bundle") if m.invoked_as_script?diff --git a/bin/ember-cli b/bin/ember-cliindex 9ccb5bc53fa..ef567053d95 100755--- a/bin/ember-cli+++ b/bin/ember-cli@@ -117,12 +117,17 @@ if ARGV.include?("-u") || ARGV.include?("--unicorn")endThread.new do- Open3.popen2e(pnpm_env, "pnpm", "ember-tsc", "-b", "--watch", "--preserveWatchOutput") do |i, oe, t|+ Open3.popen2e(+ pnpm_env,+ "pnpm",+ "ember-tsc",+ "-b",+ "--watch",+ "--preserveWatchOutput",+ ) do |i, oe, t|tsc_pid = t.pidputs "Ember TSC running on PID: #{tsc_pid}"- oe.each do |line|- puts "[ember-tsc] #{line}"- end+ oe.each { |line| puts "[ember-tsc] #{line}" }endif process_running?(unicorn_pid)puts "[bin/ember-cli] ember-tsc process stopped. Terminating unicorn."diff --git a/bin/lint b/bin/lintindex 551f6019935..d028e0976bd 100755--- a/bin/lint+++ b/bin/lint@@ -4,6 +4,8 @@require "optparse"require "open3"require "shellwords"+require "yaml"+require "pathname"class LefthookLinterdef initialize(options = {})@@ -19,25 +21,37 @@ class LefthookLinterEVERYTHING = ["ALL FILES"]def run- files_to_lint = determine_files+ files = determine_filesif @fix- run_fix_mode(files_to_lint)+ run_fix_mode(files)else- run_check_mode(files_to_lint)+ run_check_mode(files)endendprivatedef determine_files- return recent_files if @recent- return staged_files if @staged- return unstaged_files if @unstaged- return wip_files if @wip- return @files if [email protected]?+ files =+ if @recent+ recent_files+ elsif @staged+ staged_files+ elsif @unstaged+ unstaged_files+ elsif @wip+ wip_files+ elsif [email protected]?+ @files+ else+ return EVERYTHING+ end- EVERYTHING+ files+ .map { |f| normalize_relative_path(f) }+ .select { |f| File.file?(f) && lintable_file?(f) }+ .uniqenddef recent_files@@ -46,58 +60,40 @@ class LefthookLinterlog_files = log_output.lines.map(&:strip).reject(&:empty?)- tracked_out, tracked_status = Open3.capture2("git", "ls-files")- untracked_out, untracked_status =- Open3.capture2("git", "ls-files", "--others", "--exclude-standard")- return [] unless tracked_status.success? && untracked_status.success?+ tracked_out, _ = Open3.capture2("git", "ls-files")+ untracked_out, _ = Open3.capture2("git", "ls-files", "--others", "--exclude-standard")tracked = Set.new(tracked_out.lines.map(&:strip))untracked = Set.new(untracked_out.lines.map(&:strip))- # Only keep log files that are still tracked, then add all untracked- candidates = Set.new+ candidates = []log_files.each { |f| candidates << f if tracked.include?(f) }- untracked.each { |f| candidates << f }-- candidates.select { |f| File.file?(f) && lintable_file?(f) }+ candidates + untracked.to_aenddef staged_filesgit_output, status = Open3.capture2("git", "diff", "--cached", "--name-only")return [] unless status.success?-- git_output.lines.map(&:strip).reject(&:empty?).select { |f| File.file?(f) && lintable_file?(f) }+ git_output.lines.map(&:strip).reject(&:empty?)enddef unstaged_filesgit_output, status = Open3.capture2("git", "diff", "--name-only")return [] unless status.success?-- git_output.lines.map(&:strip).reject(&:empty?).select { |f| File.file?(f) && lintable_file?(f) }+ git_output.lines.map(&:strip).reject(&:empty?)enddef wip_files- # Get files changed since main branch- main_diff_output, main_status = Open3.capture2("git", "diff", "main...HEAD", "--name-only")- main_files = main_status.success? ? main_diff_output.lines.map(&:strip).reject(&:empty?) : []-- # Get staged files- staged_output, staged_status = Open3.capture2("git", "diff", "--cached", "--name-only")- staged = staged_status.success? ? staged_output.lines.map(&:strip).reject(&:empty?) : []+ main_diff_output, _ = Open3.capture2("git", "diff", "main...HEAD", "--name-only")+ main_files = main_diff_output.lines.map(&:strip).reject(&:empty?)- # Get unstaged files- unstaged_output, unstaged_status = Open3.capture2("git", "diff", "--name-only")- unstaged = unstaged_status.success? ? unstaged_output.lines.map(&:strip).reject(&:empty?) : []-- # Combine all files and remove duplicates- all_files = Set.new(main_files + staged + unstaged)- all_files.select { |f| File.file?(f) && lintable_file?(f) }+ main_files + staged_files + unstaged_filesenddef lintable_file?(file)# Skip certain directories and filesif file.include?("node_modules") || file.include?("vendor") || file.include?("tmp") ||- file.include?(".git") || file == "database.yml"+ file.include?(".git") || file == "config/database.yml"return falseend@@ -157,27 +153,67 @@ class LefthookLinterendend- def run_lefthook_command(hook_name, files)- cmd = ["pnpm", "lefthook", "run", hook_name]+ GLOB_FLAGS = File::FNM_PATHNAME | File::FNM_EXTGLOB | File::FNM_CASEFOLD | File::FNM_DOTMATCH+ LEFTHOOK_CONFIG_PATH = File.expand_path("../lefthook.yml", __dir__)+ PROJECT_ROOT = File.expand_path("..", __dir__)++ def run_lefthook_command(hook, files)+ commands = lefthook_config.dig(hook, "commands")++ if !files.empty? && commands+ normalized = files.map { |f| normalize_relative_path(f) }+ any = false- # Only add file arguments if we have specific files- # For lints and fix-staged without files, let lefthook handle all files- files.each { |file| cmd << "--file" << file } unless files.empty?+ commands.each do |name, config|+ filtered = filter_files_for_command(normalized, config)+ next if filtered.empty?- # Add verbose flag if requested+ any = true+ exec_lefthook(hook, name, filtered)+ end+ puts "No matching linters for provided files." if !any && @verbose+ else+ exec_lefthook(hook, nil, files)+ end+ end++ def exec_lefthook(hook, command, files)+ cmd = ["pnpm", "lefthook", "run", hook]+ cmd << "--command" << command if command+ files.each { |f| cmd << "--file" << f }cmd << "--verbose" if @verboseputs "Running: #{cmd.shelljoin}" if @verbose+ exit 1 unless system(*cmd)+ end- # Use system to preserve colored output and proper exit codes- success = system(*cmd)+ def lefthook_config+ @lefthook_config ||= YAML.load_file(LEFTHOOK_CONFIG_PATH)+ end- unless success- puts "❌ Linting failed"- exit 1+ def filter_files_for_command(files, config)+ globs = Array(config["glob"]).compact+ excludes = Array(config["exclude"]).compact++ files.select do |file|+ matches_includes =+ globs.empty? || globs.any? { |pattern| File.fnmatch?(pattern, file, GLOB_FLAGS) }+ matches_excludes = excludes.any? { |pattern| File.fnmatch?(pattern, file, GLOB_FLAGS) }+ matches_includes && !matches_excludesend+ end- puts "✅ All linting checks passed" if @verbose+ def normalize_relative_path(file)+ cleaned = file.start_with?("./") ? file[2..] : file+ path = Pathname.new(cleaned)+ if path.absolute?+ begin+ path = path.relative_path_from(Pathname.new(PROJECT_ROOT))+ rescue ArgumentError+ # leave as is if it's outside the repo+ end+ end+ path.to_sendenddiff --git a/bin/rake b/bin/rakeindex b699951a809..78174bcdc73 100755--- a/bin/rake+++ b/bin/rake@@ -1,13 +1,13 @@#!/usr/bin/env ruby# frozen_string_literal: true-if ENV['RAILS_ENV'] == 'test' && ENV['LOAD_PLUGINS'].nil?- if ARGV.include?('db:migrate') || ARGV.include?('parallel:migrate')+if ENV["RAILS_ENV"] == "test" && ENV["LOAD_PLUGINS"].nil?+ if ARGV.include?("db:migrate") || ARGV.include?("parallel:migrate")STDERR.puts "You are attempting to run migrations in your test environment and are not loading plugins, setting LOAD_PLUGINS to 1"- ENV['LOAD_PLUGINS'] = '1'+ ENV["LOAD_PLUGINS"] = "1"endend-require_relative '../config/boot'-require 'rake'+require_relative "../config/boot"+require "rake"Rake.application.rundiff --git a/bin/rubocop b/bin/rubocopindex d0c48829311..cb690b3558b 100755--- a/bin/rubocop+++ b/bin/rubocop@@ -9,8 +9,7 @@#require "pathname"-ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",- Pathname.new(__FILE__).realpath)+ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", Pathname.new(__FILE__).realpath)bundle_binstub = File.expand_path("../bundle", __FILE__)@@ -18,8 +17,10 @@ if File.file?(bundle_binstub)if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/load(bundle_binstub)else- abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.-Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")+ abort(+ "Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.+Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.",+ )endenddiff --git a/lefthook.yml b/lefthook.ymlindex 0e501733ff9..3fb16eeb0e4 100644--- a/lefthook.yml+++ b/lefthook.yml@@ -7,6 +7,8 @@ output:- execution_info- skips+glob_matcher: doublestar+pre-commit:parallel: trueskip:@@ -14,49 +16,55 @@ pre-commit:- rebasecommands:rubocop:+ exclude:+ - "bin/notify_file_change"+ - "bin/docker/**/*"glob:- - "*.{rb,rake,thor}"- - "bin/*"+ - "**/*.{rb,rake,thor}"+ - "bin/**/*"- "Gemfile"run: bundle exec rubocop --force-exclusion {staged_files}syntax_tree:+ exclude:+ - "bin/notify_file_change"+ - "bin/docker/**/*"glob:- - "*.{rb,rake,thor}"- - "bin/*"+ - "**/*.{rb,rake,thor}"+ - "bin/**/*"- "Gemfile"run: bundle exec stree check Gemfile {staged_files}prettier:glob:- - "app/assets/stylesheets/*.{css,scss}"- - "frontend/*.{js,gjs,scss,css,cjs,mjs}"- - "plugins/*.{js,gjs,scss,css,cjs,mjs}"- - "themes/*.{js,gjs,scss,css,cjs,mjs}"+ - "app/assets/stylesheets/**/*.{css,scss}"+ - "frontend/**/*.{js,gjs,scss,css,cjs,mjs}"+ - "plugins/**/*.{js,gjs,scss,css,cjs,mjs}"+ - "themes/**/*.{js,gjs,scss,css,cjs,mjs}"run: pnpm pprettier --list-different {staged_files}eslint:glob:- - "frontend/*.{js,gjs}"- - "plugins/*.{js,gjs}"- - "themes/*.{js,gjs}"+ - "frontend/**/*.{js,gjs}"+ - "plugins/**/*.{js,gjs}"+ - "themes/**/*.{js,gjs}"run: pnpm eslint --quiet {staged_files}ember-template-lint:glob:- - "frontend/*.gjs"- - "plugins/*.gjs"- - "themes/*.gjs"+ - "frontend/**/*.gjs"+ - "plugins/**/*.gjs"+ - "themes/**/*.gjs"run: pnpm ember-template-lint {staged_files}yaml-syntax:- glob: "*.{yaml,yml}"+ glob: "**/*.{yaml,yml}"# database.yml is an erb file not a yaml file- exclude: "database.yml"+ exclude: "config/database.yml"run: bundle exec yaml-lint {staged_files}i18n-lint:glob: "**/{client,server}.en.yml"run: bundle exec ruby script/i18n_lint.rb {staged_files}stylelint:glob:- - "app/assets/stylesheets/*.scss"- - "plugins/*/assets/stylesheets/*.scss"- - "themes/*.scss"+ - "app/assets/stylesheets/**/*.scss"+ - "plugins/**/assets/stylesheets/**/*.scss"+ - "themes/**/*.scss"run: pnpm stylelint {staged_files}fix-staged:@@ -64,39 +72,45 @@ fix-staged:commands:prettier:glob:- - "app/assets/stylesheets/*.{css,scss}"- - "frontend/*.{js,gjs,scss,css,cjs,mjs}"- - "plugins/*.{js,gjs,scss,css,cjs,mjs}"- - "themes/*.{js,gjs,scss,css,cjs,mjs}"+ - "app/assets/stylesheets/**/*.{css,scss}"+ - "frontend/**/*.{js,gjs,scss,css,cjs,mjs}"+ - "plugins/**/*.{js,gjs,scss,css,cjs,mjs}"+ - "themes/**/*.{js,gjs,scss,css,cjs,mjs}"run: pnpm pprettier --write {staged_files}eslint:glob:- - "frontend/*.{js,gjs}"- - "plugins/*.{js,gjs}"- - "themes/*.{js,gjs}"+ - "frontend/**/*.{js,gjs}"+ - "plugins/**/*.{js,gjs}"+ - "themes/**/*.{js,gjs}"run: pnpm eslint --fix {staged_files}ember-template-lint:glob:- - "frontend/*.gjs"- - "plugins/*.gjs"- - "themes/*.gjs"+ - "frontend/**/*.gjs"+ - "plugins/**/*.gjs"+ - "themes/**/*.gjs"run: pnpm ember-template-lint --fix {staged_files}stylelint:glob:- - "app/assets/stylesheets/*.scss"- - "plugins/*/assets/stylesheets/*.scss"- - "themes/*.scss"+ - "app/assets/stylesheets/**/*.scss"+ - "plugins/**/assets/stylesheets/**/*.scss"+ - "themes/**/*.scss"run: pnpm stylelint --fix {staged_files}rubocop:+ exclude:+ - "bin/notify_file_change"+ - "bin/docker/**/*"glob:- - "*.{rb,rake,thor}"- - "bin/*"+ - "**/*.{rb,rake,thor}"+ - "bin/**/*"- "Gemfile"run: bundle exec rubocop --force-exclusion -A {staged_files}syntax_tree:+ exclude:+ - "bin/notify_file_change"+ - "bin/docker/**/*"glob:- - "*.{rb,rake,thor}"- - "bin/*"+ - "**/*.{rb,rake,thor}"+ - "bin/**/*"- "Gemfile"run: bundle exec stree write Gemfile {staged_files}@@ -119,8 +133,8 @@ lints:commands:rubocop:glob:- - "*.{rb,rake,thor}"- - "bin/*"+ - "**/*.{rb,rake,thor}"+ - "bin/**/*"- "Gemfile"run: bundle exec rubocopprettier:@@ -132,9 +146,9 @@ lints:stylelint:run: pnpm lint:cssyaml-syntax:- glob: "*.{yaml,yml}"+ glob: "**/*.{yaml,yml}"# database.yml is an erb file not a yaml file- exclude: "database.yml"+ exclude: "config/database.yml"run: bundle exec yaml-lint {all_files}i18n-lint:glob: "**/{client,server}.en.yml"