update no posix in regular expression to match changes in project
MODIFY
packages/@romejs/diagnostics/descriptions.ts
packages/@romejs/diagnostics/descriptions.ts
@@ -478,6 +478,11 @@ export const descriptions = createMessages(
message: `Duplicate group name <emphasis>${name}</emphasis> in regular expression`,
}),
+ NO_POSIX_IN_REGULAR_EXPRESSION: {
+ category: 'lint/noPosixInRegularExpression',
+ message: 'POSIX Character Classes and Collating Sequences are not supported in ECMAscript Regular Expressions',
+ },
+
NO_REFERENCE_TO_NON_EXISTING_GROUP: (name: string) => ({
category: 'lint/noReferenceToNonExistingGroup',
message: `Reference to non-existent group <emphasis>"${name}"</emphasis>`,

MODIFY
packages/@romejs/js-compiler/transforms/lint/noPosixInRegularExpression.test.ts
packages/@romejs/js-compiler/transforms/lint/noPosixInRegularExpression.test.ts
* LICENSE file in the root directory of this source tree.
*/
-import test from '@romejs/test';
-import {testLint} from '../../api/lint.test';
-import {PartialDiagnostic} from '@romejs/diagnostics/types';
+import {test} from 'rome';
+// import {testLint} from '../../api/lint.test';
+import {testLintMultiple} from '../../api/lint.test';
-test('no POSIX in regular expression', async t => {
- function checkCategory(diagnostic: PartialDiagnostic): Boolean {
- return diagnostic.category === 'lint/noPosixInRegularExpression';
- }
+// import {PartialDiagnostic} from '@romejs/diagnostics/types';
+test('no POSIX in regular expression', async (t) => {
+ // function checkCategory(diagnostic: PartialDiagnostic): Boolean {
+ // return diagnostic.category === 'lint/noPosixInRegularExpression';
+ // }
- const testCases = [
+ // const testCases = [
+ // 'const pattern = /[[:alpha:]]/',
+ // 'const pattern = /[[.ch.]]/',
+ // ];
+
+ // for (const testCase of testCases) {
+ // const {diagnostics} = await testLint(testCase);
+ // console.log(diagnostics)
+ // t.truthy(diagnostics.find(checkCategory));
+ // }
+
+ testLintMultiple(t, [
'const pattern = /[[:alpha:]]/',
'const pattern = /[[.ch.]]/',
- ];
-
- for (const testCase of testCases) {
- const {diagnostics} = await testLint(testCase);
- t.truthy(diagnostics.find(checkCategory));
- }
+ ], {category: 'lint/noPosixInRegularExpression'});
});

MODIFY
packages/@romejs/js-compiler/transforms/lint/noPosixInRegularExpression.ts
packages/@romejs/js-compiler/transforms/lint/noPosixInRegularExpression.ts
*/
import {AnyNode, RegExpCharSet} from '@romejs/js-ast';
-import {Path, Context} from '@romejs/js-compiler';
-
-function checkRegEx(node: RegExpCharSet, context: Context): RegExpCharSet {
- node.body.forEach((currNode, i) => {
+import {Path, CompilerContext} from '@romejs/js-compiler';
+import {descriptions} from '@romejs/diagnostics';
+// import { isStrictBody } from '@romejs/js-parser/parser';
+function checkRegEx(
+ node: RegExpCharSet,
+ context: CompilerContext,
+): RegExpCharSet {
+ node.body.forEach(
+ (currNode, i) => {
const nextNode = node.body[i + 1];
const lastNode = node.body[node.body.length - 1];
- if (
- currNode.type === 'RegExpCharacter' &&
- currNode.value === '[' &&
- nextNode.type === 'RegExpCharacter' &&
- (nextNode.value === ':' || nextNode.value === '.') &&
- lastNode.type === 'RegExpCharacter' &&
- lastNode.value === nextNode.value
- ) {
- context.addNodeDiagnostic(currNode, {
- fixable: false,
- category: 'lint/noPosixInRegularExpression',
- message:
- 'POSIX Character Classes and Collating Sequences are not supported in ECMAscript Regular Expressions',
- });
+ if (currNode.type === 'RegExpCharacter' && currNode.value === '[' &&
+ nextNode && nextNode.type === 'RegExpCharacter' &&
+ (nextNode.value ===
+ ':' ||
+ nextNode.value === '.') && lastNode.type === 'RegExpCharacter' &&
+ lastNode.value === nextNode.value) {
+ context.addNodeDiagnostic(
+ currNode,
+ descriptions.LINT.NO_POSIX_IN_REGULAR_EXPRESSION,
+ {fixable: false},
+ );
}
- });
+ },
+ );
return node;
}
@@ -37,7 +40,7 @@ export default {
enter(path: Path): AnyNode {
const {context, node} = path;
- if (node.type === 'RegExpCharSet') {
+ if (node.type === 'RegExpCharSet' && node.body.length > 2) {
return checkRegEx(node, context);
}

update no posix in regular expression to match changes in project