naming-convention
What it does
Section titled “What it does”Reports a name that does not follow the style set for what it names: operations, fragments, variables, fields, arguments, types, enum values and directives. PascalCase and camelCase allow letters and digits only, snake_case and UPPER_CASE forbid the other case; leading underscores are ignored. No fix: renaming changes the schema or the queries that use it.
Why it matters
Section titled “Why it matters”Names that follow one convention are predictable: a reader can guess the name of a thing, tell a type from a variable at a glance and search for them. A name in another style stands out as a mistake or as code from another project. The convention itself is a choice of the project, which is why the expression is an option.
To fix, rename the declaration and its uses.
Example
Section titled “Example”query get_user($User_id: ID) { user }fragment user_fields on User { id }type user_account { first_name(Arg_one: Int): String }enum Color { red GREEN }directive @Auth on FIELDinput Filter { Name: String }type _Ok { __typename: String }Configuration
Section titled “Configuration”graphql: lint: rules: naming-convention: level: warn # off (default), warn, error options: operations: "PascalCase" fragments: "PascalCase" variables: "camelCase" fields: "camelCase" arguments: "camelCase" types: "PascalCase" enum_values: "UPPER_CASE" directives: "camelCase"hcl: lint: rules: naming-convention: level: warn # off (default), warn, error options: operations: "PascalCase" fragments: "PascalCase" variables: "camelCase" fields: "camelCase" arguments: "camelCase" types: "PascalCase" enum_values: "UPPER_CASE" directives: "camelCase"java: lint: rules: naming-convention: level: warn # off (default), warn, error options: operations: "PascalCase" fragments: "PascalCase" variables: "camelCase" fields: "camelCase" arguments: "camelCase" types: "PascalCase" enum_values: "UPPER_CASE" directives: "camelCase"| Option | Type | Default | Description |
|---|---|---|---|
operations |
string | "PascalCase" |
Style of operation names. Values: PascalCase, camelCase, snake_case, UPPER_CASE, off |
fragments |
string | "PascalCase" |
Style of fragment names. Values: PascalCase, camelCase, snake_case, UPPER_CASE, off |
variables |
string | "camelCase" |
Style of variable names. Values: PascalCase, camelCase, snake_case, UPPER_CASE, off |
fields |
string | "camelCase" |
Style of field and input field names in definitions. Values: PascalCase, camelCase, snake_case, UPPER_CASE, off |
arguments |
string | "camelCase" |
Style of argument names in definitions. Values: PascalCase, camelCase, snake_case, UPPER_CASE, off |
types |
string | "PascalCase" |
Style of type names. Values: PascalCase, camelCase, snake_case, UPPER_CASE, off |
enum_values |
string | "UPPER_CASE" |
Style of enum values. Values: PascalCase, camelCase, snake_case, UPPER_CASE, off |
directives |
string | "camelCase" |
Style of directive names. Values: PascalCase, camelCase, snake_case, UPPER_CASE, off |
Enabled by the presets: graphql/graphql-eslint-recommended, java/google.
Suppress one line with sudsy-disable-next-line naming-convention in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.
| Tool | Rule | Match | What differs |
|---|---|---|---|
| checkstyle | PackageName |
full | |
| checkstyle | TypeName |
full | |
| checkstyle | MethodName |
partial | Google’s camel segments and @Test method names are patterns of the options methods and test_methods. |
| checkstyle | MemberName |
full | |
| checkstyle | NonConstantFieldName |
partial | The member pattern of Google’s name rule. |
| checkstyle | ConstantName |
partial | A static final field or an interface field; no exceptions list. |
| checkstyle | ParameterName |
full | |
| checkstyle | CatchParameterName |
full | |
| checkstyle | LocalVariableName |
partial | No separate pattern for for variables. |
| graphql-eslint | naming-convention |
partial | Leading and trailing underscores are no-name-underscore. No forbiddenPrefixes, forbiddenSuffixes, requiredPrefixes, requiredSuffixes or ignorePattern; no per-kind styles for the root types, interfaces versus objects, or inputs versus objects; PascalCase and camelCase accept runs of capitals (HTTPServer) that change-case rewrites. |
| tflint | terraform_naming_convention |
partial | One format for every kind of block (tflint sets one per kind) and no custom regular expression. |