Rules / Style / non-constant-identifier-names

non-constant-identifier-names

lint/style/non-constant-identifier-names
recommended
Same as non_constant_identifier_names · Dart lints

Flags non-constant identifiers that are not written in lowerCamelCase.

Dart convention reserves lowerCamelCase for everything that holds a runtime value — non-const variables and fields, formal and closure parameters, for-in loop variables, function and method names, and named constructors. Consistent casing lets readers distinguish these from types (UpperCamelCase) and compile-time constants at a glance. The check mirrors the analyzer's isLowerCamelCase: leading underscores are ignored, an all-underscore wildcard name is accepted, a single uppercase letter is tolerated, and the remainder must begin with a lowercase letter or $ and contain no further underscores. Type names and constants are covered by separate rules and are out of scope here.

Invalid

example.dartdart
// Non-constant identifiers must be lowerCamelCase.

int My_Var = 0;

void Foo() {}

void f(int Bad_Param) {}

class A {
  void Some_Method() {}

  A.My_Named();
}

void g() {
  var Local_Var = 1;
  print(Local_Var);
}
Name non-constant identifiers using lowerCamelCase.
2
3int My_Var = 0;
Name non-constant identifiers using lowerCamelCase.
4
5void Foo() {}
Name non-constant identifiers using lowerCamelCase.
6
7void f(int Bad_Param) {}
Name non-constant identifiers using lowerCamelCase.
9class A {
10 void Some_Method() {}
Name non-constant identifiers using lowerCamelCase.
11
12 A.My_Named();
Name non-constant identifiers using lowerCamelCase.
15void g() {
16 var Local_Var = 1;

Valid

example.dartdart
// lowerCamelCase non-constant identifiers.

int myVar = 0;

void foo() {}

void f(int goodParam) {}

class A {
  void someMethod() {}

  A.myNamed();
}

void g() {
  var localVar = 1;
  var _private = 2;
  print(localVar + _private);
}

void h(int _) {}

How to configure

Set the severity of non-constant-identifier-names in your falcon.json:

falcon.jsonjson
{
  "linter": {
    "rules": {
      "style": {
        "non-constant-identifier-names": "error"
      }
    }
  }
}