Skip to content

feat(no-template-literal-title): disallow template literals in titles - #500

Open
unlikelyzero wants to merge 1 commit into
mskelton:mainfrom
unlikelyzero:feat/no-template-literal-title
Open

feat(no-template-literal-title): disallow template literals in titles#500
unlikelyzero wants to merge 1 commit into
mskelton:mainfrom
unlikelyzero:feat/no-template-literal-title

Conversation

@unlikelyzero

Copy link
Copy Markdown
Collaborator

Closes #499

Adds no-template-literal-title, which reports a template literal used as the
title of test, test.describe, or test.step.

A test title is an identifier — reporters group by it, --grep matches it, and
flake dashboards key on it. Interpolating a value means the title only exists
once the data does, and changes when the data changes: --grep "login as admin"
matches nothing predictable from the source, and a title that reads
upload invoice-8842.pdf on one run is a different test to anything tracking
results over time.

The rule splits that into two reports, because the two cases deserve different
treatment:

Case Message Fix
test(`login as ${role}`) interpolatedTitle none — the right replacement is the author's call
test(`checkout completes`) staticTemplateLiteral autofixed to 'checkout completes'

The fixer escapes \ and ', and declines to fix multiline titles or ones
whose cooked value is null (invalid escape sequence), so it can never change
the name that ends up in a report.

Options

ignore: Array<'test' | 'test.describe' | 'test.step'> skips the listed
callers, mirroring the ignore option on prefer-lowercase-title. A suite that
deliberately generates parameterized test names can set { ignore: ['test'] }
and still get stable test.describe and test.step titles.

Not added to the recommended config — parameterized titles are an established
Playwright pattern, so whether to forbid them is a project-level policy choice.

Tests

34 cases covering modifiers (.only, .skip, .fixme, .describe.only),
globalAliases, fixer escaping of backticks/quotes/backslashes, the unfixable
multiline case, both option paths, and the negatives — anonymous
test.describe(() => {}), string concatenation, and template literals in
locators or test.describe.configure().

A test title is an identifier: reporters group by it, --grep matches it,
and flake dashboards key on it. Interpolating a value into the title of
test, test.describe, or test.step means the name only exists once the data
does and changes when the data changes, so grep stops working and result
history fragments across runs.

Report interpolated titles with no autofix, since choosing a stable
replacement is the author's call. Report template literals with no
interpolation separately and fix them to string literals, escaping quotes
and backslashes and bailing on multiline or invalid-escape titles so the
reported name cannot change.

An ignore option skips test, test.describe, or test.step individually,
mirroring prefer-lowercase-title, so suites that deliberately parameterize
test names can keep the rule for describes and steps. Not enabled in the
recommended config.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New rule proposal: no-template-literal-title

1 participant