Add noTemplateCurlyInString lint rule
MODIFY
packages/@romejs/js-compiler/__rtests__/lint.ts
packages/@romejs/js-compiler/__rtests__/lint.ts
@@ -376,3 +376,30 @@ test('no delete vars', async t => {
},
]);
});
+
+test('no template curly in string', async t => {
+ const res = await testLint(
+ `
+ const user = "Faustina";
+ const helloUser = "Hello, \${user}!";
+
+ // mark consts as used
+ console.log(user, helloUser)
+ `,
+ LINT_ENABLED_FORMAT_DISABLED_CONFIG,
+ );
+
+ t.looksLike(res.diagnostics, [
+ {
+ category: 'lint/noTemplateCurlyInString',
+ filename: 'unknown',
+ language: 'js',
+ message: 'Unexpected template string expression.',
+ mtime: undefined,
+ sourceType: 'module',
+ origins: [{category: 'lint'}],
+ end: {column: 39, index: 69, line: 3},
+ start: {column: 22, index: 52, line: 3},
+ },
+ ]);
+});

MODIFY
packages/@romejs/js-compiler/transforms/lint/index.ts
packages/@romejs/js-compiler/transforms/lint/index.ts
@@ -17,6 +17,7 @@ import noDuplicateKeys from './noDuplicateKeys';
import disallowVar from './disallowVar';
import noUnsafeFinally from './noUnsafeFinally';
import noDeleteVars from './noDeleteVars';
+import noTemplateCurlyInString from './noTemplateCurlyInString';
export const lintTransforms = [
undeclaredVariables,
@@ -31,4 +32,5 @@ export const lintTransforms = [
disallowVar,
noUnsafeFinally,
noDeleteVars,
+ noTemplateCurlyInString,
];

ADD
packages/@romejs/js-compiler/transforms/lint/noTemplateCurlyInString.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 {Path} from '@romejs/js-compiler';
+import {markup} from '@romejs/string-markup';
+
+export default {
+ name: 'noTemplateCurlyInString',
+ enter(path: Path) {
+ const {node, context} = path;
+
+ if (node.type === 'StringLiteral') {
+ const regex = /\$\{[^}]+\}/u;
+
+ if (regex.test(node.value)) {
+ context.addNodeDiagnostic(node, {
+ category: 'lint/noTemplateCurlyInString',
+ message: markup`Unexpected template string expression.`,
+ });
+ }
+ }
+
+ return node;
+ },
+};

Add noTemplateCurlyInString lint rule