Skip to content

Latest commit

Β 

History

History
109 lines (78 loc) Β· 2.58 KB

File metadata and controls

109 lines (78 loc) Β· 2.58 KB

comment-content

πŸ“ Enforce better comment content.

🚫 This rule is disabled in the following configs: βœ… recommended, β˜‘οΈ unopinionated.

πŸ”§ This rule is automatically fixable by the --fix CLI option.

This rule enforces curated replacements in comments. It is useful for common name, brand, and acronym casing corrections such as nodejs β†’ Node.js, and for project-specific prose preferences.

This rule is not a spellchecker. It only checks known replacement patterns.

It only reports one replacement per comment at a time.

It focuses on prose-like comment text and skips obvious non-prose regions such as code snippets, including commented-out multi-line code, links, paths, structured data, and command examples.

Examples

// ❌
// nodejs uses javascript.

// βœ…
// Node.js uses JavaScript.
// ❌
// See the github issue.

// βœ…
// See the GitHub issue.
// ❌
// The application stores png files.

// βœ…
// The app stores PNG files.

Options

Type: object

checkUniformCase

Type: boolean
Default: true

By default, the rule re-cases matching tokens regardless of their case, including all-lowercase (json) and all-uppercase (JSON) ones.

Pass checkUniformCase: false to only correct tokens that already mix upper- and lower-case, such as Github β†’ GitHub. All-lowercase and all-uppercase tokens are then left alone, as their casing is often intentional. Replacements that change the actual letters (such as application β†’ app, or your own typo fixes) still apply regardless of case.

'unicorn/comment-content': [
	'error',
	{
		checkUniformCase: false,
	},
]

replacements

Type: object

You can extend the default replacements by passing the replacements option.

The key is treated as a regex. By default, custom replacements are case-sensitive.

'unicorn/comment-content': [
	'error',
	{
		replacements: {
			'\\bteh\\b': 'the',
			'\\bto do\\b': {
				replacement: 'TODO',
				caseSensitive: false,
			},
			'\\bnode\\.?js\\b': false,
		},
	},
]

extendDefaultReplacements

Type: boolean
Default: true

Pass extendDefaultReplacements: false to override the default replacements completely.

'unicorn/comment-content': [
	'error',
	{
		extendDefaultReplacements: false,
		replacements: {
			'\\bteh\\b': 'the',
		},
	},
]