add lint/noDelete
MODIFY
packages/@romejs/diagnostics/categories.ts
packages/@romejs/diagnostics/categories.ts
@@ -35,6 +35,7 @@ export type DiagnosticCategory =
| 'lint/noCompareNegZero'
| 'lint/noCondAssign'
| 'lint/noDebugger'
+ | 'lint/noDelete'
| 'lint/noDeleteVars'
| 'lint/noDupeArgs'
| 'lint/noDuplicateCase'

MODIFY
packages/@romejs/diagnostics/descriptions.ts
packages/@romejs/diagnostics/descriptions.ts
@@ -473,6 +473,10 @@ export const descriptions = createMessages({
category: 'lint/noDupeArgs',
message: markup`Duplicate argument <emphasis>${name}</emphasis> in function definition`,
}),
+ NO_DELETE: {
+ category: 'lint/noDelete',
+ message: `Unexpected 'delete' operator.`,
+ },
NO_DELETE_VARS: {
category: 'lint/noDeleteVars',
message: 'Variables should not be deleted.',

MODIFY
packages/@romejs/js-compiler/lint/rules/index.ts
packages/@romejs/js-compiler/lint/rules/index.ts
@@ -20,6 +20,7 @@ import noCatchAssign from './noCatchAssign';
import noCompareNegZero from './noCompareNegZero';
import noCondAssign from './noCondAssign';
import noDebugger from './noDebugger';
+import noDelete from './noDelete';
import noDeleteVars from './noDeleteVars';
import noDupeArgs from './noDupeArgs';
import noDuplicateCase from './noDuplicateCase';
@@ -66,6 +67,7 @@ export const lintTransforms = [
noCompareNegZero,
noCondAssign,
noDebugger,
+ noDelete,
noDeleteVars,
noDupeArgs,
noDuplicateCase,

ADD
packages/@romejs/js-compiler/lint/rules/noDelete.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, TransformExitResult} from '@romejs/js-compiler';
+import {
+ assignmentExpression,
+ memberExpression,
+ referenceIdentifier,
+} from '@romejs/js-ast';
+import {descriptions} from '@romejs/diagnostics';
+
+export default {
+ name: 'noDelete',
+ enter(path: Path): TransformExitResult {
+ const {context, node} = path;
+
+ if (
+ node.type === 'UnaryExpression' &&
+ node.operator === 'delete' &&
+ node.argument.type === 'MemberExpression'
+ ) {
+ const left = node.argument;
+ return context.addFixableDiagnostic(
+ {
+ old: node,
+ fixed: assignmentExpression.create(
+ {
+ operator: '=',
+ left: memberExpression.create({
+ object: left.object,
+ property: left.property,
+ }),
+ right: referenceIdentifier.create({
+ name: 'undefined',
+ }),
+ },
+ node,
+ ),
+ },
+ descriptions.LINT.NO_DELETE,
+ );
+ }
+
+ return node;
+ },
+};

add lint/noDelete