Linters & Formatters
Formatters, lint rule engines and static type checkers for each ecosystem, from ESLint and Prettier to ruff, RuboCop and golangci-lint. Asked because the formatter/linter split shapes every CI gate.
on this pageshowhide
explore
- ESLint29 questions
- Rules & Severity6 questions
- Flat Config6 questions
- Plugins and Shared Configs6 questions
- TypeScript Integration5 questions
- CI and Editor Integration6 questions
- Prettier6 questions
- Biomeempty
- blackempty
- ruffempty
- mypyempty
- pyrightempty
- Ktlint2 questions
- Detekt4 questions
- golangci-lintempty
- goimportsempty
- PHPStan10 questions
- Rule Levels & Config5 questions
- Baselines & PHPDoc Types5 questions
- PHP CS Fixer6 questions
- PHPCodeSniffer6 questions
- RuboCop18 questions
- Departments & Cop Settings6 questions
- Autocorrect & Todo Files6 questions
- Standard Ruby6 questions
- SwiftLint6 questions
- SwiftFormat6 questions
- shellcheckempty
- StyleCopempty
questions
93 · 10 sectionsWhat exit code does the ESLint CLI return when a run finds only warnings, and how do you make CI fail on them?
basics
~20 sExit code 0: warnings alone never fail an ESLint run, and only errors return 1. Add --max-warnings 0 and any warning makes ESLint exit with 1; exit code 2 means ESLint itself hit a configuration problem or crashed.
In ESLint 10, what does `eslint.config.js` export, and how do you apply a rule only to test files?
basics
~20 sAn eslint.config.js file exports an array of configuration objects, usually wrapped in defineConfig(). To target tests, append an object whose files key holds a test glob such as **/*.test.js and whose rules apply only to those files.
In ESLint, what do the rule severities "off", "warn" and "error" do, and which one makes a lint run fail?
basics
~20 s"off" (0) disables a rule, "warn" (1) reports its violations without touching ESLint's exit code, and "error" (2) reports them and makes the run exit with code 1, so only error-level rules fail a build by default.
Why can't ESLint lint a TypeScript file with its default parser, and what does the typescript-eslint package add so that it can?
basics
~20 sESLint's default parser, Espree, reads only JavaScript, so a type annotation is a parsing error. The typescript-eslint package adds a parser that turns TypeScript into ESLint's tree format, a plugin of TypeScript rules, and presets that wire both in.
In a CI pipeline, why run `prettier --check` rather than `prettier --write`, and what do its exit codes 0, 1 and 2 mean?
basics
~20 sprettier --check only reports unformatted files and exits 1 when any exist, so CI fails without touching the checkout; --write rewrites files in place for local use. Exit 0 means everything is formatted, exit 2 means Prettier hit an error.
In an ESLint flat config, what does `eslint-config-prettier` do, and where must it go in the exported array?
basics
~10 seslint-config-prettier turns off every ESLint rule that is unnecessary with Prettier or would fight it. In flat config you import eslint-config-prettier/flat and place it after the configs it must override, because later objects win.
In Prettier, how is the `.prettierrc` that applies to a file found, and how do `overrides` give some files different options?
basics
~20 sPrettier searches from the formatted file's directory upward and uses the first config it finds; there is no global config. Inside it, overrides entries match files globs, optionally minus excludeFiles, and apply their own options.
How does Prettier 3 decide where to break lines, and why is `printWidth` not a hard limit like ESLint's `max-len`?
basics
~20 sPrettier parses the file into an AST, throws away nearly all original layout and reprints it, breaking a construct only when it does not fit printWidth (default 80). That width is a goal, so some lines run longer.
Why do Prettier's docs advise against running Prettier as an ESLint rule through `eslint-plugin-prettier`, and what setup replaces it?
basics
~20 sRunning Prettier as an ESLint rule turns every layout difference into a lint error: red squiggles while typing, slower runs than Prettier alone, and one more layer that can break. Run Prettier directly instead, with eslint-config-prettier turning ESLint's formatting rules off.
In ktlint 1.x, how do you suppress a single rule violation for one declaration or file?
basics
~20 sAnnotate the code with Kotlin's @Suppress using the fully qualified rule id, for example @Suppress("ktlint:standard:function-naming") on the declaration, or @file:Suppress(...) at the top of the file. The old ktlint-disable comments were removed in ktlint 1.0.
Why can ktlintFormat succeed while ktlintCheck still reports violations on the same code?
basics
~20 sNot every ktlint rule can autocorrect. Rules that need a human decision, such as naming rules and max-line-length, only report; the format task rewrites what it can and leaves those violations in place, so the check task still fails on them.
Which code metrics does detekt's complexity rule set measure, and what are its default limits?
basics
~10 sdetekt's complexity set measures branching and size: CyclomaticComplexMethod and CognitiveComplexMethod per function, LongMethod and LargeClass in lines, NestedBlockDepth, ComplexCondition, LongParameterList, TooManyFunctions. Defaults sit near 60 lines per function and 600 per class.
How do you suppress a single detekt finding in Kotlin source without editing detekt.yml?
basics
~20 sAnnotate the smallest declaration that contains the finding with Kotlin's @Suppress, passing detekt's rule id — for example @Suppress("MagicNumber") on one function. detekt reuses the standard annotation; a configured alias or the rule set id also works.
A detekt rule fires constantly on your codebase — how do you decide between tuning, scoping, and disabling it?
basics
~20 sFirst ask whether the findings are real. If the rule is right but over-broad, narrow it with its own options or an excludes path glob; move the number only if the codebase's idiom genuinely differs; set active: false only when the rule contradicts a deliberate convention.
Why does detekt's autoCorrect option leave most findings unfixed in a Gradle build?
basics
~20 sBecause autoCorrect only reaches rules that implement a correction. Most detekt rules describe a design problem with no mechanical fix — a long method or a magic number cannot be rewritten automatically — so they stay reported no matter how the flag is set.
In PHPStan 2, what are rule levels 0 to 10, and what do the main levels add as you move up?
basics
~20 sPHPStan's rule levels are a cumulative strictness dial from 0 (unknown classes, functions, wrong argument counts) to 10 (errors even for implicit mixed); each level adds checks to all lower ones, and max is an alias for the highest.
In PHPStan, how do you generate a baseline, what does each entry record, and how does the baseline shrink as errors get fixed?
basics
~20 svendor/bin/phpstan analyse --generate-baseline writes phpstan-baseline.neon, an ignoreErrors list with message, identifier, count and path per file, which you include in phpstan.neon; fixed errors leave entries unmatched, PHPStan reports them, and you regenerate to shrink it.
In a phpstan.neon file, what do level, paths, excludePaths and includes do, and how do command-line arguments interact with them?
basics
~20 sUnder parameters, level sets the rule level, paths lists what to analyse and excludePaths removes fnmatch patterns; includes pulls in other config files. A --level or paths given on the command line replace the config values rather than merging with them.
In PHPStan, what do the PHPDoc types list<T> and array{...} shapes express that PHP's native array type cannot?
basics
~20 sNative array only says the value is an array. list<T> means keys 0, 1, 2 with no gaps and values of type T; array{id: int, name?: string} describes each key and its type, optional keys included.
In PHPStan, how should a plain string from config become a class-string: narrowed with class_exists() or forced with an inline @var?
basics
~20 sNarrow it: after if (class_exists($name)) PHPStan treats $name as class-string, and the check also protects runtime. An inline @var is trusted without proof, so the docs call it a last resort and prefer fixing the type at its source.
What does PHP CS Fixer do to your PHP code, and how do its fix and check commands differ?
basics
~20 sPHP CS Fixer rewrites PHP source so it matches a configured set of rules; fix changes the files, while check (fix --dry-run) changes nothing and only reports which files would change, exiting with bit 8 set.
In PHP CS Fixer, how do you configure .php-cs-fixer.dist.php with a Finder and rule sets such as @PER-CS or @PHP8x5Migration?
basics
~20 sThe committed .php-cs-fixer.dist.php is a PHP file that returns a PhpCsFixer\Config whose Finder selects the files and whose setRules() array enables rule sets like @PER-CS or @PHP8x5Migration plus individual rules, which can be tuned or switched off.
How would you use PHP CS Fixer to reformat a whole PHP codebase to PER Coding Style in one commit without disrupting the team?
basics
~20 sPin PHP CS Fixer and a versioned set such as @PER-CS3x0, keep risky rules out, preview with check --diff, apply fix in a commit that contains nothing else, list that commit in .git-blame-ignore-revs, and start enforcing with check.
In PHP CS Fixer, what makes a rule risky, and how should a team enable risky rules with --allow-risky or setRiskyAllowed()?
basics
~10 sA risky PHP CS Fixer rule is one whose rewrite can change how the code behaves, such as strict_param or declare_strict_types; they run only when the config calls setRiskyAllowed(true) or the command passes --allow-risky=yes.
When would you choose PHP CS Fixer over PHP_CodeSniffer, or run both, to enforce a PHP team's coding style?
basics
~20 sPHP CS Fixer suits teams that want every rule fixed automatically, including modernising and risky rewrites; PHP_CodeSniffer suits teams that must also report conventions no tool can fix. Running both works when only one of them owns layout.
In PHP_CodeSniffer, what is the difference between the phpcs and phpcbf commands, and which violations can phpcbf fix?
basics
~20 sphpcs scans PHP files against a coding standard and reports violations without changing anything; phpcbf reads the same ruleset and rewrites files, fixing only the violations whose sniffs implement an automatic fix and leaving the rest for a human.
In a PHP_CodeSniffer phpcs.xml.dist ruleset, how do rule ref, exclude and properties decide which sniffs run and how they behave?
basics
~20 sA phpcs.xml.dist ruleset pulls in a whole standard, a category, one sniff or one message with rule ref, removes parts of it with exclude, and tunes a sniff's public settings with properties, so the whole team runs the same checks.
In PHP_CodeSniffer, how do phpcs:ignore, phpcs:disable and phpcs:enable comments differ, and why should they name a sniff code?
basics
~10 sphpcs:ignore suppresses one line, phpcs:disable suppresses everything until phpcs:enable or the end of the file, and phpcs:ignoreFile skips the file; naming a sniff code limits the suppression so other violations still surface.
In PHP_CodeSniffer, how do errors, warnings and severity levels decide which violations a phpcs run reports and fails on?
basics
~20 sEach PHP_CodeSniffer message is an error or a warning with a severity, 5 by default; phpcs shows it only if that severity reaches the threshold, 5 by default, and every shown message, warnings included, makes the exit code non-zero.
How do you write a custom PHP_CodeSniffer 4.0 sniff, and what do its register() and process() methods do?
basics
~10 sA custom sniff is a class implementing PHP_CodeSniffer\Sniffs\Sniff inside a standard's Sniffs/Category folder: register() returns the token types it listens for, and process() inspects each matching token and reports violations through the File object.
In a .rubocop.yml file, how do you disable a cop, change one of its options and exclude files, and what is a department?
basics
~20 sA .rubocop.yml keys each cop by qualified name, such as Layout/LineLength: Enabled: false switches it off, keys like Max tune it, and Exclude skips paths. A department (Lint, Style, Layout, Metrics...) groups cops and can be configured as one.
What is Standard Ruby (the standard gem), how do you run it with standardrb or rake standard, and how does it differ from configuring RuboCop yourself?
basics
~20 sStandard Ruby is a gem that runs RuboCop with a fixed, non-configurable ruleset. Run standardrb (or rake standard after requiring standard/rake), add --fix for safe corrections; it ignores .rubocop.yml and reads only options from .standard.yml.
In RuboCop, what is the difference between rubocop -a and rubocop -A, and how do a cop's Safe and SafeAutoCorrect settings decide what -a changes?
basics
~20 srubocop -a applies only corrections RuboCop marks safe; rubocop -A also applies unsafe ones that may change behaviour. A correction counts as safe only when the cop has both Safe and SafeAutoCorrect true, which is the default.
In Ruby code checked by RuboCop, how do rubocop:disable, rubocop:enable and rubocop:todo comments work, and how do you keep them tightly scoped?
basics
~20 sA # rubocop:disable Cop comment at the end of a line silences that line; on its own line it silences until # rubocop:enable Cop. rubocop:todo is an alias marking a suppression to revisit. -- reason documents why.
In SwiftLint's .swiftlint.yml, how do opt_in_rules, disabled_rules and only_rules differ, and which of them can you combine?
basics
~20 sSwiftLint starts from its default rule set: disabled_rules removes default rules, opt_in_rules adds rules that are off by default, and only_rules replaces the whole set with an explicit list, so it cannot be combined with the other two.
Adopting SwiftLint on a 250k-line app with thousands of warnings, how do --write-baseline, --baseline and --strict make CI fail only on new violations?
basics
~20 sRun swiftlint lint --write-baseline once to record every current violation in a JSON file, commit it, and have CI run swiftlint lint --strict --baseline with that file: known violations are filtered out, and any new warning, now an error, fails the job.
In SwiftLint's .swiftlint.yml, how do you write a custom_rules entry that bans print() in production code without flagging strings, comments or tests?
basics
~20 sAdd a custom_rules entry with a regex for print(, match_kinds: identifier so matches inside strings and comments are dropped, an excluded path regex for test files, and a message and severity; with only_rules, list custom_rules too.
In SwiftLint, how do swiftlint:disable:next, :this and :previous comments scope a suppression, and what goes wrong with a bare swiftlint:disable?
basics
~20 sA swiftlint:disable comment with :next, :this or :previous suppresses the named rules on exactly one line: the following line, the comment's own line, or the line before. A bare swiftlint:disable stays in force until a matching enable or the end of the file.
In an Xcode project, when do you run SwiftLint as SwiftLintBuildToolPlugin rather than a Run Script phase, and what breaks with each?
basics
~20 sUse SwiftLintBuildToolPlugin when each target can be linted with one .swiftlint.yml inside the project and a pinned package version; use a Run Script phase when you need --config, --fix or one run over all targets, and then turn off user script sandboxing for it.
In SwiftFormat, how does a .swiftformat file choose rules and options, and how does the tool find the file that applies?
basics
~10 sA .swiftformat file is SwiftFormat command-line arguments written one per line: --rules, --disable and --enable pick rules, other flags set options. SwiftFormat applies every .swiftformat on the path to each file, deeper ones overriding.
In SwiftFormat, how do swiftformat:disable, :next and swiftformat:options comments keep a hand-aligned table of Swift constants from being reformatted?
basics
~10 sWrap the table in // swiftformat:disable consecutiveSpaces and // swiftformat:enable consecutiveSpaces, or use // swiftformat:disable:next for one line. swiftformat:options changes option values for part of a file instead of switching rules off.
What does SwiftFormat's --lint mode do differently from a normal run, and what do --lenient and its exit codes mean for a CI step?
basics
~20 sWith --lint, SwiftFormat formats each file in memory, writes nothing, reports every line that would change and exits 1 if any file needs formatting. --lenient keeps the report but exits 0; exit 70 means bad input or configuration.
Why should a project give SwiftFormat its Swift version with --swift-version or a .swift-version file, and what goes wrong without one?
basics
~20 sSome SwiftFormat rules produce syntax only newer Swift accepts, so with no version set they stay off and every run warns. Declare the oldest Swift compiler that builds the project with --swift-version or a .swift-version file.
A project runs SwiftFormat and SwiftLint, and trailing commas and multiline opening braces keep flipping between builds; why, and how do you stop it?
basics
~20 sBoth tools have layout rules with opposite defaults: SwiftFormat adds trailing commas and moves a multiline statement's brace onto its own line, while SwiftLint's trailing_comma and opening_brace want the reverse. Give each concern one owner and align the other.