implemented no-empty-character-class
MODIFY
packages/@romejs/js-compiler/transforms/lint/index.ts
packages/@romejs/js-compiler/transforms/lint/index.ts
@@ -15,6 +15,7 @@ import noAsyncPromiseExecutor from './noAsyncPromiseExecutor';
import noLabelVar from './noLabelVar';
import noDuplicateKeys from './noDuplicateKeys';
import disallowVar from './disallowVar';
+import noEmptyCharacterClass from './noEmptyCharacterClass';
export const lintTransforms = [
undeclaredVariables,
@@ -27,4 +28,5 @@ export const lintTransforms = [
noLabelVar,
noDuplicateKeys,
disallowVar,
+ noEmptyCharacterClass
];

ADD
packages/@romejs/js-compiler/transforms/lint/noEmptyCharacterClass.ts
+/**
+ * Copyright (c) Facebook, Inc. and its affiliates.
+ *
+ * This source code is licensed under the MIT license found in the
+ * LICENSE file in the root directory of this source tree.
+ */
+
+
+import {AnyNode} from '@romejs/js-ast';
+import {Path} from '@romejs/js-compiler';
+
+/*
+ * plain-English description of the following regexp:
+ * 1. `^` fix the match at the beginning of the string
+ * 2. `([^\\[]|\\.|\[([^\\\]]|\\.)+\])*`: regexp contents; 0 or more of the following
+ * 2.0. `[^\\[]`: any character that's not a `\` or a `[` (anything but escape sequences and character classes)
+ * 2.1. `\\.`: an escape sequence
+ * 2.2. `\[([^\\\]]|\\.)+\]`: a character class that isn't empty
+ * 3. `$`: fix the match at the end of the string
+ */
+
+const regex = /^([^\\[]|\\.|\[([^\\\]]|\\.)+\])*$/u;
+
+export default {
+ name: 'noEmptyCharacterClass',
+ enter(path: Path): AnyNode {
+ const {context, node} = path;
+
+ if (node.type === "RegExpLiteral" && !regex.test(node.pattern)) {
+ context.addNodeDiagnostic(node, {
+ category: 'lint/noEmptyCharacterClass',
+ message:
+ 'Empty character classes in regular expressions are not allowed',
+ });
+ }
+
+ return node;
+ },
+};

implemented no-empty-character-class