A meticulously crafted Ruby gem to enhance the cleanliness and structure of your project's files. This tool ensures consistency and uniformity across various formats, including Ruby, ERB, YAML, Markdown, JSON, JS, CSS, SASS, LESS, and other formats supported by Prettier.
The cleaner recognizes and caters to various file formats:
| File Type | File Extension | Processor |
|---|---|---|
| ERB | .html.erb , .html |
htmlbeautifier && erb-lint |
| Ruby | .rb, .rake, Gemfile, Rakefile, Brewfile, .axlsx, .cap, .gemspec, .ru, .podspec, .jbuilder, .rabl, .thor, Berksfile, Capfile, Guardfile, Podfile, Thorfile, Vagrantfile, files starting with #!/usr/bin/env ruby |
rubocop |
| YAML | .yml (only files in locales folder) |
ImmosquareYaml |
| JS | .js, .mjs, .cjs, .jsx, .ts, .tsx, .js.erb, .mjs.erb, .cjs.erb, .jsx.erb, .ts.erb, .tsx.erb, .coffee.erb |
eslint |
| JSON | .json |
ImmosquareExtensions |
| Markdown | .md, .md.erb |
ImmosquareCleaner |
| Shell | .sh, bash, zsh, zshrc, bashrc, bash_profile, zprofile |
shfmt |
| Others | Any other format | prettier |
You can view the specific configurations for all supported linters in the linters folder of the repository.
The gem includes custom RuboCop cops:
| Cop | Description |
|---|---|
CustomCops/Style/CommentNormalization |
Normalizes comment formatting |
CustomCops/Style/FontAwesomeNormalization |
Standardizes Font Awesome class names (fas -> fa-solid) |
CustomCops/Style/AlignAssignments |
Aligns consecutive variable assignments (disabled by default) |
CustomCops/Style/InlineMultilineCalls |
Collapses multi-line calls (default: link_to) onto a single line |
CustomCops/Style/KwargPriorityOrder |
Reorders kwargs of link_to so :remote/:method come first |
Style/MethodCallWithArgsParentheses |
Allows parentheses omission in Jbuilder blocks and .jbuilder files |
The gem includes custom erb_lint linters for ERB files:
| Linter | Description |
|---|---|
CustomSingleLineIfModifier |
Converts <% if cond %><%= x %><% end %> to <%= x if cond %> |
CustomHtmlToContentTag |
Converts <div class="x"><%= y %></div> to <%= content_tag(:div, y, :class => "x") %> |
CustomAlignConsecutiveCalls |
Aligns args of consecutive ERB calls (default: link_to) when keys/arity match |
Requires bun and shfmt (brew install shfmt).
gem "immosquare-cleaner", :group => :developmentThe config file is optional. If you want to use it, it must be placed in the config/initializers folder and must be named immosquare-cleaner.rb
ImmosquareCleaner.config do |config|
config.rubocop_options = "--your-rubocop-options-here"
config.htmlbeautifier_options = "--your-htmlbeautifier-options-here"
config.erblint_options = "--your-erblint-options-here"
config.exclude_files = ["db/schema.rb", "db/seeds.rb", "..."]
endbundle exec immosquare-cleaner path/to/your/file.rb| Option | Description |
|---|---|
-p, --prevent-concurrent-write |
Wait 2 seconds, clean a copy of the file in /tmp, then overwrite the original only if it hasn't changed in the meantime. Use when an IDE may be saving the file in parallel (e.g. editor on-save hook). |
-h, --help |
Print usage and exit. |
On first run, the CLI runs bun install automatically if the gem's node_modules/ is missing.
ImmosquareCleaner.clean("path/to/your/file.rb")To clean every source file of a Rails app in bulk (onboarding, cleaner upgrade, large refactor):
bundle exec rake immosquare_cleaner:clean_appThe task is parallelized via threads (defaults to min(nprocessors, 8) since linters shell out and release the GVL). Override with:
CLEANER_THREADS=4 bundle exec rake immosquare_cleaner:clean_appGenerated/non-source folders (app/assets/builds, app/assets/fonts, app/assets/images, coverage, db, log, node_modules, public, test, tmp, vendor) and binary/lock files (.lock, .lockb, .otf, .ttf, .png, .jpg, .jpeg, .gif, .svg, .ico, .webp, .csv) are skipped.
Simply install the immosquare-vscode extension from the VS Code marketplace.
That's it!
TypeScript 7 is installed as @typescript/native, but TypeScript 7.0 does not expose the stable programmatic API required by typescript-eslint and SonarJS. The typescript dependency therefore resolves to the fixed 6.0.3 npm tarball; using the tarball prevents bun update --latest from replacing the linter API. Remove this compatibility lock when typescript-eslint supports the TypeScript 7.1 API.
bundle exec rake testContributions are welcome! Please open an issue or submit a pull request on our GitHub repository.
This gem is available under the terms of the MIT License.