js-compiler: add noDebugger to lint
MODIFY
packages/@romejs/js-compiler/__rtests__/lint.ts
packages/@romejs/js-compiler/__rtests__/lint.ts
@@ -500,3 +500,22 @@ test('no import assign', async t => {
}
}
});
+
+test('no debugger', async t => {
+ const goodRes = await testLint(
+ `const test = { debugger: 1 };
+ test.debugger;
+ console.log(test); // To not trigger the unused var rule.
+ `,
+ LINT_ENABLED_FORMAT_DISABLED_CONFIG,
+ );
+
+ t.is(goodRes.diagnostics.length, 0);
+
+ const badRes = await testLint(
+ 'debugger;',
+ LINT_ENABLED_FORMAT_DISABLED_CONFIG,
+ );
+
+ t.snapshot(badRes.diagnostics);
+});

MODIFY
packages/@romejs/js-compiler/transforms/lint/index.ts
packages/@romejs/js-compiler/transforms/lint/index.ts
@@ -12,6 +12,7 @@ import sparseArray from './sparseArray';
import noAsyncPromiseExecutor from './noAsyncPromiseExecutor';
import noCompareNegZero from './noCompareNegZero';
import noCondAssign from './noCondAssign';
+import noDebugger from './noDebugger';
import noDuplicateKeys from './noDuplicateKeys';
import noDupeArgs from './noDupeArgs';
import noLabelVar from './noLabelVar';
@@ -41,4 +42,5 @@ export const lintTransforms = [
noDeleteVars,
noTemplateCurlyInString,
noImportAssign,
+ noDebugger,
];

ADD
packages/@romejs/js-compiler/transforms/lint/noDebugger.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';
+
+export default {
+ name: 'noDebugger',
+ enter(path: Path): AnyNode {
+ const {node} = path;
+
+ if (node.type === 'DebuggerStatement') {
+ path.context.addNodeDiagnostic(node, {
+ category: 'lint/noDebugger',
+ message: "Unexpected 'debugger' statement",
+ });
+ }
+
+ return node;
+ },
+};

js-compiler: add noDebugger to lint