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

page 2 of 2

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

How would you use PHPStan's @template to type a collection class so that its elements keep their type through add(), get() and foreach?

level: seniorimportance: should knowfreq 35%

basics

~20 s

Declare @template T above the class, use T in @param and @return tags, declare @implements IteratorAggregate<int, T> for foreach, and type usages as Collection<User>; PHPStan then infers User from get() and foreach and rejects adding other types.

open as a page

What do PHPStan's Bleeding Edge and the phpstan-strict-rules extension each add beyond rule levels, and how do you enable them?

level: seniorimportance: should knowfreq 30%

basics

~10 s

Bleeding Edge, enabled by including phar://phpstan.phar/conf/bleedingEdge.neon, turns on the next major version's rules and behaviour early; phpstan-strict-rules is an opinionated extension of extra checks, enabled through phpstan/extension-installer or by including its rules.neon.

open as a page

You are introducing PHPStan into a 300,000-line legacy PHP codebase; how do you choose the starting level and configure the first runs?

level: seniorimportance: should knowfreq 40%

basics

~20 s

Start at level 0 over your own code only, fix configuration noise such as unknown classes with scanDirectories, bootstrapFiles and framework extensions, get to zero, gate CI there, then raise one level at a time, expecting level 6 to be the big jump.

open as a page

After a one-off rubocop -A run on a Ruby 4.0 app, tests fail with FrozenError and NoMethodError; what did the run change, and how should it have been done?

level: seniorimportance: should knowfreq 35%

basics

~20 s

rubocop -A applied corrections marked unsafe: the frozen-string-literal comment froze mutated literals (FrozenError), and x && x.foo became x&.foo, which breaks when x is false. Run -a first, then -A one cop at a time with tests between.

open as a page

In RuboCop, what does rubocop --auto-gen-config write into .rubocop_todo.yml, and how do you keep that todo file shrinking instead of rotting?

level: seniorimportance: should knowfreq 50%

basics

~20 s

--auto-gen-config writes .rubocop_todo.yml, which excludes each offending file per cop (up to 15, then disables the cop) or raises Metrics Max values, and links it via inherit_from. Delete entries as you fix code; --report-unused-todo-entries fails on stale ones.

open as a page

After a RuboCop upgrade, a run warns about pending cops and about `require: rubocop-performance` - what does each warning mean, and how do you fix the .rubocop.yml?

level: seniorimportance: should knowfreq 35%

basics

~20 s

Pending cops are new cops that stay off until you decide; set each one's Enabled, or NewCops for all or per department. The require: warning means the gem is now a plugin, so list it under plugins: instead.

open as a page

How do you add rules to Standard Ruby with plugins or extend_config in .standard.yml, and why can neither change Standard's own rules?

level: seniorimportance: should knowfreq 25%

basics

~20 s

List lint_roller plugin gems such as standard-rails under plugins:, or RuboCop YAML files under extend_config:. Configuration is first-in-wins: Standard's built-in plugins load first, so later plugins and files can add cops but never reconfigure ones already set.

open as a page

Adopting RuboCop on a five-year-old Ruby codebase, how do you decide which departments and cops the team enforces, and how do you encode that in .rubocop.yml?

level: principalimportance: should knowfreq 25%

basics

~20 s

Enforce what prevents bugs first: Lint and Security fail the build; Layout is autocorrected once; Style and Metrics are chosen deliberately. Encode it with department and cop Enabled, Severity, AllCops FailLevel and, for a strict opt-in list, DisabledByDefault.

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

Why is RuboCop slow when an editor or git hook runs it per file, and what do its --server mode and --lsp language server change?

level: middleimportance: nice to knowfreq 25%

basics

~20 s

Each rubocop invocation spends much of its time loading RuboCop and its plugins. --server keeps a background process with everything loaded and forwards later commands to it; --lsp runs a long-lived language server that editors talk to directly.

open as a page

Your team enforces a phpcs.xml.dist ruleset on every pull request; what can break when upgrading PHP_CodeSniffer from 3.x to 4.0?

level: seniorimportance: nice to knowfreq 15%

basics

~20 s

Upgrading to PHP_CodeSniffer 4.0 changes exit codes, the default standard (PEAR to PSR12) and output streams, removes the @codingStandardsIgnore annotations, some sniffs and the string array-property syntax, and renames several error codes, so check scripts, suppressions and the ruleset.

open as a page

How do PHP CS Fixer's cache file and parallel runner speed up runs, and when can each cause trouble?

level: seniorimportance: nice to knowfreq 15%

basics

~20 s

PHP CS Fixer skips files whose content hash matches .php-cs-fixer.cache and reruns everything when the rules or tool version change, and since 3.94 it spreads files across worker processes by default; stale caches and constrained CI machines are the usual sources of trouble.

open as a page

You are starting a new open-source Ruby gem that supports Ruby 3.2 and later: how would you set up Standard, and when would plain RuboCop be the better choice?

level: seniorimportance: nice to knowfreq 20%

basics

~20 s

Put standard in the Gemfile's development group, set ruby_version: 3.2 in .standard.yml, and make rake's default task run tests and standard. Choose plain RuboCop to tune cops, enforce Metrics, or use features newer than Standard's pinned RuboCop.

open as a page

showing 31–46 of 46