Skip to content

Latest commit

 

History

History
61 lines (41 loc) · 1.64 KB

sort-flags.md

File metadata and controls

61 lines (41 loc) · 1.64 KB
pageClass sidebarDepth title description since
rule-details
0
regexp/sort-flags
require regex flags to be sorted
v0.9.0

regexp/sort-flags

💼 This rule is enabled in the ✅ plugin:regexp/recommended config.

🔧 This rule is automatically fixable by the --fix CLI option.

require regex flags to be sorted

📖 Rule Details

The flags of JavaScript regular expressions should be sorted alphabetically because the flags of the .flags property of RegExp objects are always sorted. Not sorting flags in regex literals misleads readers into thinking that the order may have some purpose which it doesn't.

/* eslint regexp/sort-flags: "error" */

/* ✓ GOOD */
var foo = /abc/
var foo = /abc/iu
var foo = /abc/gimsuy

/* ✗ BAD */
var foo = /abc/mi
var foo = /abc/us

🔧 Options

Nothing.

❤️ Compatibility

This rule was taken from eslint-plugin-clean-regex.
This rule is compatible with clean-regex/sort-flags rule.

🚀 Version

This rule was introduced in eslint-plugin-regexp v0.9.0

🔍 Implementation