Package com.google.javascript.jscomp
Class GoogleCodingConvention
java.lang.Object
com.google.javascript.jscomp.CodingConventions.Proxy
com.google.javascript.jscomp.GoogleCodingConvention
- All Implemented Interfaces:
CodingConvention,Serializable
This describes the Google-specific JavaScript coding conventions.
Within Google, variable names are semantically significant.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.google.javascript.jscomp.CodingConvention
CodingConvention.AssertionFunctionSpec, CodingConvention.Bind, CodingConvention.DelegateRelationship, CodingConvention.ObjectLiteralCast, CodingConvention.SubclassRelationship, CodingConvention.SubclassType -
Field Summary
Fields inherited from class com.google.javascript.jscomp.CodingConventions.Proxy
nextConvention -
Constructor Summary
ConstructorsConstructorDescriptionBy default, decorate the ClosureCodingConvention.GoogleCodingConvention(CodingConvention convention) Decorates a wrapped CodingConvention. -
Method Summary
Modifier and TypeMethodDescriptionbooleanisConstant(String name) This checks whether a given variable name, such as a name in all-caps should be treated as if it had the @const annotation.booleanisConstantKey(String name) This checks whether a given key of an object literal, such as a name in all-caps should be treated as if it had the @const annotation.booleanisExported(String name, boolean local) Checks whether a global variable or function name should be treated as exported, or externally referenceable.booleanisOptionalParameter(Node parameter) This checks whether a given parameter name should be treated as an optional parameter as far as type checking or function call arg count checking is concerned.booleanChecks whether a name should be considered private.booleanisValidEnumKey(String key) This checks that a givenkeymay be used as a key for an enum.booleanisVarArgsParameter(Node parameter) This checks whether a given parameter should be treated as a marker for a variable argument list function.Methods inherited from class com.google.javascript.jscomp.CodingConventions.Proxy
applyDelegateRelationship, applySingletonGetter, applySubclassRelationship, checkForCallingConventionDefiningCalls, defineDelegateProxyPrototypeProperties, describeFunctionBind, describeFunctionBind, extractClassNameIfProvide, extractClassNameIfRequire, getAbstractMethodName, getAssertionFunctions, getClassesDefinedByCall, getDelegateRelationship, getDelegateSuperclassName, getExportPropertyFunction, getExportSymbolFunction, getGlobalObject, getIndirectlyDeclaredProperties, getObjectLiteralCast, getSingletonGetterClassName, identifyTypeDeclarationCall, isExported, isInlinableFunction, isPropertyTestFunction, isPrototypeAlias, isSuperClassReference
-
Constructor Details
-
GoogleCodingConvention
public GoogleCodingConvention()By default, decorate the ClosureCodingConvention. -
GoogleCodingConvention
Decorates a wrapped CodingConvention.
-
-
Method Details
-
isConstant
This checks whether a given variable name, such as a name in all-caps should be treated as if it had the @const annotation.This enforces the Google const name convention, that the first character after the last $ must be an upper-case letter and all subsequent letters must be upper case. The name must be at least 2 characters long.
Examples:
aaa Not constant - lower-case letters in the name A Not constant - too short goog$A Constant - letters after the $ are upper-case. AA17 Constant - digits can appear after the first letter goog$7A Not constant - first character after the $ must be upper case. $A Constant - doesn't have to be anything in front of the $- Specified by:
isConstantin interfaceCodingConvention- Overrides:
isConstantin classCodingConventions.Proxy- Parameters:
name- potentially constant variable name- Returns:
trueif the name should be treated as a constant.
-
isConstantKey
Description copied from interface:CodingConventionThis checks whether a given key of an object literal, such as a name in all-caps should be treated as if it had the @const annotation.- Specified by:
isConstantKeyin interfaceCodingConvention- Overrides:
isConstantKeyin classCodingConventions.Proxy
-
isValidEnumKey
This checks that a givenkeymay be used as a key for an enum.This enforces Google's convention about enum key names. They must match the regular expression
[A-Z0-9][A-Z0-9_]*.Examples:
- A
- 213
- FOO_BAR
- Specified by:
isValidEnumKeyin interfaceCodingConvention- Overrides:
isValidEnumKeyin classCodingConventions.Proxy- Parameters:
key- the potential key to an enum- Returns:
trueif thekeymay be used as an enum key,falseotherwise
-
isOptionalParameter
This checks whether a given parameter name should be treated as an optional parameter as far as type checking or function call arg count checking is concerned. Note that an optional function parameter may be declared as a simple type and is automatically converted to a union of the declared type and Undefined.In Google code, parameter names beginning with
opt_are treated as optional arguments.- Specified by:
isOptionalParameterin interfaceCodingConvention- Overrides:
isOptionalParameterin classCodingConventions.Proxy- Parameters:
parameter- The parameter's node.- Returns:
trueif the parameter should be treated as an optional parameter.
-
isVarArgsParameter
Description copied from interface:CodingConventionThis checks whether a given parameter should be treated as a marker for a variable argument list function. A VarArgs parameter must be the last parameter in a function declaration.- Specified by:
isVarArgsParameterin interfaceCodingConvention- Overrides:
isVarArgsParameterin classCodingConventions.Proxy- Parameters:
parameter- The parameter's node.- Returns:
trueif the parameter should be treated as a variable length parameter.
-
isExported
Checks whether a global variable or function name should be treated as exported, or externally referenceable.In Google code, any global name starting with an underscore is considered exported.
- Specified by:
isExportedin interfaceCodingConvention- Overrides:
isExportedin classCodingConventions.Proxy- Parameters:
name- A global variable or function name.local-trueif the name is a local variable.- Returns:
trueif the name should be considered exported.
-
isPrivate
Checks whether a name should be considered private. Private global variables and functions can only be referenced within the source file in which they are declared. Private properties and methods should only be accessed by the class that defines them.In Google code, private names end with an underscore, and exported names are never considered private (see
isExported(java.lang.String, boolean)).- Specified by:
isPrivatein interfaceCodingConvention- Overrides:
isPrivatein classCodingConventions.Proxy- Parameters:
name- The name of a global variable or function, or a method or property.- Returns:
trueif the name should be considered private.
-