Skip to content

[Linting Rule] Code Clones

github-actions[bot] edited this page Nov 8, 2026 · 1 revision

Generated from 'wiki-linter.ts' on 2026-11-08, 08:41:20 UTC (v2.17.4), do not edit directly.

Code Clones [overview]

smell experimental readability

This rule is a best-effort rule.

Finds duplicated code (code clones) with a configurable selection of AST, token, and fingerprint based algorithms.
This linting rule is implemented in src/linter/rules/code-clones.ts.

Configuration

Linting rules can be configured by passing a configuration object to the linter query as shown in the example below. The code-clones rule accepts the following configuration options:

Examples

normalize <- function(v) {
	m <- mean(v)
	(v - m) / sd(v)
}
scale_it <- function(values) {
	mu <- mean(values)
	(values - mu) / sd(values)
}

The linting query can be used to run this rule on the above example:

[ { "type": "linter",   "rules": [ { "name": "code-clones",     "config": {} } ] } ]

Results (prettified and summarized):

Query: linter (1 ms)
   ╰ Code Clones (code-clones):
       ╰ uncertain:
           ╰ Code is a clone of scale_it at <input 0>:6.13-9.1 (gst, similarity 1.00)

More examples are the test cases in test/functionality/linter/lint-code-clones.test.ts.

Clone this wiki locally

⌂ 换网址