internal/contributor-info/linters.md
These linters support the ShakaCode Style Guidelines
If you haven't tried the autofix options for eslint and rubocop, you're seriously missing out!
bundle exec rubocop -a
eslint --fix .
or
npm run lint -- --fix
Autofixing is a HUGE time saver!
Prettier handles code formatting for JavaScript, TypeScript, CSS, and Markdown files.
⚠️ CRITICAL: Prettier is the SOLE authority for formatting. Never manually format code.
# Check formatting
pnpm start format.listDifferent
# Fix formatting (includes all linters)
rake autofix
# Or format only
pnpm start format
When resolving merge conflicts, NEVER manually format. Follow this sequence:
git add . (or specific files)rake autofix (fixes all formatting + linting)git add . (if autofix made changes)git rebase --continue or git commitWhy this matters: Manual formatting during conflict resolution creates "formatting wars" between tools and leads to back-and-forth formatting changes in PRs.
See the ESLint website for more information.
See the documentation first.
Rule severity is configured with 'off', 'warn' or 'error'. In older configurations you can see 0, 1, and 2 instead.
Rules can also take a few additional options. In this case, the rule can be set to an array, the first item of which is the severity and the rest are options.
See file .eslintrc for examples of configuration
Rules can also be specified in the code file to be linted, as JavaScript comments. This can be useful when the rule is a one-off or is a override to a project-wide rule.
For example, if your file assumes a few globals and you have the no-undef rule set in the .eslintrc file, you might want to relax the rule in the current file.
/* global $, window, angular */
// rest of code
It's also useful to disable ESLint for particular lines or blocks of lines.
console.log('console.log not allowed'); // eslint-disable-line
alert('alert not allowed'); // eslint-disable-line no-alert
/* eslint-disable no-console, no-alert */
console.log('more console.log');
alert('more alert');
/* eslint-enable no-console, no-alert */
You can disable all rules for a line or block, or only specific rules, as shown above.
See the RuboCop website.