logoESLint React

context-name

Enforces identifier names assigned from 'createContext' calls to be a valid component name with the suffix 'Context'.

Full Name in eslint-plugin-react-naming-convention

react-naming-convention/context-name

Full Name in @eslint-react/eslint-plugin

@eslint-react/naming-convention-context-name

Presets

naming-convention recommended recommended-typescript recommended-type-checked strict strict-typescript strict-type-checked

Rule Details

Enforces that the context has a valid component name with the suffix Context.

Examples

// Problem: Identifier 'theme' does not have the 'Context' suffix
const theme = createContext("");
// Problem: Identifier 'themeContext' is not PascalCase
const themeContext = createContext("");
// Recommended: PascalCase with 'Context' suffix
const ThemeContext = createContext("");
// Recommended: Name is exactly 'Context'
const Context = createContext("");
// OK: PascalCase with 'Context' suffix (MemberExpression)
obj.nested.ThemeContext = createContext("");
// OK: PascalCase with 'Context' suffix (class property)
class Foo { ThemeContext = createContext(""); }

Versions

Resources

Further Reading

On this page