skip to content

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 pageshow

explore

questions

93 · 10 sections

What exit code does the ESLint CLI return when a run finds only warnings, and how do you make CI fail on them?

level: juniorimportance: must knowfreq 38%
basics
~20 s

Exit 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.

open as a page

In ESLint 10, what does `eslint.config.js` export, and how do you apply a rule only to test files?

level: juniorimportance: must knowfreq 40%
basics
~20 s

An 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.

open as a page

In ESLint 10's flat config, how do you load a plugin, and how are its rules then named in the `rules` object?

level: juniorimportance: must knowfreq 35%
basics
~10 s

Import the plugin in eslint.config.js and register it in a config object's plugins object under a namespace you choose; each of its rules is then configured as namespace/rule-name, for example crew/no-raw-dates.

open as a page

In ESLint, what do the rule severities "off", "warn" and "error" do, and which one makes a lint run fail?

level: juniorimportance: must knowfreq 42%
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.

open as a page

Why can't ESLint lint a TypeScript file with its default parser, and what does the typescript-eslint package add so that it can?

level: juniorimportance: must knowfreq 28%
basics
~20 s

ESLint'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.

open as a page

In a CI pipeline, why run `prettier --check` rather than `prettier --write`, and what do its exit codes 0, 1 and 2 mean?

level: juniorimportance: must knowfreq 34%
basics
~20 s

prettier --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.

open as a page

In an ESLint flat config, what does `eslint-config-prettier` do, and where must it go in the exported array?

level: middleimportance: must knowfreq 24%
basics
~10 s

eslint-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.

open as a page

In Prettier, how is the `.prettierrc` that applies to a file found, and how do `overrides` give some files different options?

level: middleimportance: should knowfreq 12%
basics
~20 s

Prettier 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.

open as a page

How does Prettier 3 decide where to break lines, and why is `printWidth` not a hard limit like ESLint's `max-len`?

level: middleimportance: should knowfreq 18%
basics
~20 s

Prettier 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.

open as a page

Why do Prettier's docs advise against running Prettier as an ESLint rule through `eslint-plugin-prettier`, and what setup replaces it?

level: seniorimportance: should knowfreq 15%
basics
~20 s

Running 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.

open as a page

In ktlint 1.x, how do you suppress a single rule violation for one declaration or file?

level: juniorimportance: should knowfreq 35%
basics
~20 s

Annotate 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.

open as a page

Why can ktlintFormat succeed while ktlintCheck still reports violations on the same code?

level: middleimportance: should knowfreq 40%
basics
~20 s

Not 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.

open as a page

Which code metrics does detekt's complexity rule set measure, and what are its default limits?

level: middleimportance: must knowfreq 55%
basics
~10 s

detekt'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.

open as a page

How do you suppress a single detekt finding in Kotlin source without editing detekt.yml?

level: juniorimportance: should knowfreq 50%
basics
~20 s

Annotate 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.

open as a page

A detekt rule fires constantly on your codebase — how do you decide between tuning, scoping, and disabling it?

level: seniorimportance: should knowfreq 42%
basics
~20 s

First 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.

open as a page

Why does detekt's autoCorrect option leave most findings unfixed in a Gradle build?

level: middleimportance: nice to knowfreq 30%
basics
~20 s

Because 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.

open as a page

In PHPStan 2, what are rule levels 0 to 10, and what do the main levels add as you move up?

level: juniorimportance: must knowfreq 58%
basics
~20 s

PHPStan'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.

open as a page

In PHPStan, how do you generate a baseline, what does each entry record, and how does the baseline shrink as errors get fixed?

level: middleimportance: must knowfreq 50%
basics
~20 s

vendor/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.

open as a page

In a phpstan.neon file, what do level, paths, excludePaths and includes do, and how do command-line arguments interact with them?

level: middleimportance: must knowfreq 45%
basics
~20 s

Under 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.

open as a page

In PHPStan, what do the PHPDoc types list<T> and array{...} shapes express that PHP's native array type cannot?

level: juniorimportance: should knowfreq 42%
basics
~20 s

Native 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.

open as a page

In PHPStan, how should a plain string from config become a class-string: narrowed with class_exists() or forced with an inline @var?

level: middleimportance: should knowfreq 30%
basics
~20 s

Narrow 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.

open as a page

What does PHP CS Fixer do to your PHP code, and how do its fix and check commands differ?

level: juniorimportance: must knowfreq 50%
basics
~20 s

PHP 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.

open as a page

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?

level: middleimportance: must knowfreq 45%
basics
~20 s

The 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.

open as a page

How would you use PHP CS Fixer to reformat a whole PHP codebase to PER Coding Style in one commit without disrupting the team?

level: seniorimportance: should knowfreq 25%
basics
~20 s

Pin 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.

open as a page

In PHP CS Fixer, what makes a rule risky, and how should a team enable risky rules with --allow-risky or setRiskyAllowed()?

level: seniorimportance: should knowfreq 35%
basics
~10 s

A 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.

open as a page

When would you choose PHP CS Fixer over PHP_CodeSniffer, or run both, to enforce a PHP team's coding style?

level: seniorimportance: should knowfreq 35%
basics
~20 s

PHP 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.

open as a page

In PHP_CodeSniffer, what is the difference between the phpcs and phpcbf commands, and which violations can phpcbf fix?

level: juniorimportance: must knowfreq 55%
basics
~20 s

phpcs 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.

open as a page

In a PHP_CodeSniffer phpcs.xml.dist ruleset, how do rule ref, exclude and properties decide which sniffs run and how they behave?

level: middleimportance: must knowfreq 50%
basics
~20 s

A 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.

open as a page

In PHP_CodeSniffer, how do phpcs:ignore, phpcs:disable and phpcs:enable comments differ, and why should they name a sniff code?

level: middleimportance: should knowfreq 45%
basics
~10 s

phpcs: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.

open as a page

In PHP_CodeSniffer, how do errors, warnings and severity levels decide which violations a phpcs run reports and fails on?

level: middleimportance: should knowfreq 32%
basics
~20 s

Each 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.

open as a page

How do you write a custom PHP_CodeSniffer 4.0 sniff, and what do its register() and process() methods do?

level: seniorimportance: should knowfreq 22%
basics
~10 s

A 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.

open as a page

In a .rubocop.yml file, how do you disable a cop, change one of its options and exclude files, and what is a department?

level: juniorimportance: must knowfreq 65%
basics
~20 s

A .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.

open as a page

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?

level: juniorimportance: must knowfreq 55%
basics
~20 s

Standard 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.

open as a page

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?

level: middleimportance: must knowfreq 70%
basics
~20 s

rubocop -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.

open as a page

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?

level: middleimportance: must knowfreq 65%
basics
~20 s

A # 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.

open as a page

In RuboCop, how do you share one .rubocop.yml style across many repositories with inherit_gem or inherit_from, and which setting wins on conflict?

level: middleimportance: must knowfreq 50%
basics
~20 s

Publish the shared file in a gem and load it with inherit_gem, or point inherit_from at a path or URL. inherit_gem files load first, then inherit_from files in list order (last wins), and the repository's own settings override both.

open as a page

In SwiftLint's .swiftlint.yml, how do opt_in_rules, disabled_rules and only_rules differ, and which of them can you combine?

level: juniorimportance: must knowfreq 70%
basics
~20 s

SwiftLint 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.

open as a page

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?

level: seniorimportance: must knowfreq 58%
basics
~20 s

Run 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.

open as a page

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?

level: middleimportance: should knowfreq 45%
basics
~20 s

Add 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.

open as a page

In SwiftLint, how do swiftlint:disable:next, :this and :previous comments scope a suppression, and what goes wrong with a bare swiftlint:disable?

level: middleimportance: should knowfreq 58%
basics
~20 s

A 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.

open as a page

In an Xcode project, when do you run SwiftLint as SwiftLintBuildToolPlugin rather than a Run Script phase, and what breaks with each?

level: seniorimportance: should knowfreq 48%
basics
~20 s

Use 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.

open as a page

In SwiftFormat, how does a .swiftformat file choose rules and options, and how does the tool find the file that applies?

level: juniorimportance: should knowfreq 40%
basics
~10 s

A .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.

open as a page

In SwiftFormat, how do swiftformat:disable, :next and swiftformat:options comments keep a hand-aligned table of Swift constants from being reformatted?

level: middleimportance: should knowfreq 30%
basics
~10 s

Wrap 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.

open as a page

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?

level: middleimportance: should knowfreq 38%
basics
~20 s

With --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.

open as a page

Why should a project give SwiftFormat its Swift version with --swift-version or a .swift-version file, and what goes wrong without one?

level: middleimportance: should knowfreq 28%
basics
~20 s

Some 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.

open as a page

A project runs SwiftFormat and SwiftLint, and trailing commas and multiline opening braces keep flipping between builds; why, and how do you stop it?

level: seniorimportance: should knowfreq 42%
basics
~20 s

Both 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.

open as a page