Skip to content

(var)

variable declarations (var/let/const), including destructuring patterns

clojure
(var name? init? kind?)

Where:

  1. name: binding name or pattern *
  2. init: initializer expression *
  3. kind: the declaration keyword (var, let, or const) *

Matching:

  1. var declarations, e.g. var x = 1
  2. let declarations, e.g. let x = 1
  3. const declarations, e.g. const x = 1
  4. object destructuring, e.g. const { a } = obj
  5. array destructuring, e.g. const [a] = list

Behavior

  • When a declaration has multiple declarators, the statement matches if any declarator satisfies the constraints.

Examples

Find lingering var declarations before enforcing no-var.

clojure
(var _ _ (is var))

Selects in lines { 1 } but not in { 2, 3 }:

typescript
var legacy = 1
let modern = 2
const stable = 3

Locate environment destructuring for migration to a config loader.

clojure
(var (obj) (mem env process) (is const))

Selects in lines { 1 } but not in { 2, 3 }:

typescript
const { API_URL } = process.env
const { API_URL } = config
let { API_URL } = process.env

Identify array initializations to migrate to typed arrays.

clojure
(var _ (arr))

Selects in lines { 1, 2 } but not in { 3 }:

typescript
const items = []
let ids = [1, 2]
const count = 1

Arguments

name

• Identifier: shorthand for (id)
• Pattern: shorthand for (id)
(:kind) (:ref) (:text) (arr) (attr) (bool) (call) (child) (comp) (export) (fun) (id) (id+) (import) (jsx) (mem) (null) (num) (obj) (of) (prop) (regex) (regex+) (str) (str*) (str+) (tpl) (tpl*) (var) (:into) (:and) (:or) (:not) (:replace) (:capture)

init

• Identifier: shorthand for (id)
• Pattern: shorthand for (id)
(arr) (bin) (bool) (call) (comp) (fun) (id) (id+) (jsx) (mem) (null) (num) (obj) (of) (regex) (regex+) (str) (str*) (str+) (tpl) (tpl*) (:ref) (:into) (:and) (:or) (:not) (:text) (:kind) (:replace) (:capture)

kind

(is)
(:and) (:not) (:or) (:kind)

Does NOT support: RefinementReplacement

Copyright © 2022-present Semantic Works, Inc.