Update
This commit is contained in:
@ -32,6 +32,8 @@ export interface LocalRuleOptions {
|
||||
* @see [restrict-template-expressions](https://typescript-eslint.io/rules/restrict-template-expressions)
|
||||
*/
|
||||
'rules/restrict-template-expressions': RuleEntry<{ allow: string[] }>;
|
||||
/** Ban assignment of empty object literals `{}` and replace them with `Object.create(null)` */
|
||||
'rules/no-empty-object-literal': RuleEntry<unknown>;
|
||||
}
|
||||
|
||||
export type RuleOptions = Rules & Partial<LocalRuleOptions>;
|
||||
|
@ -27,10 +27,7 @@ export const typescriptRules: Partial<TypeScriptRules> = {
|
||||
'@typescript-eslint/no-unsafe-call': off,
|
||||
'@typescript-eslint/no-unsafe-member-access': off,
|
||||
'@typescript-eslint/no-unsafe-return': off,
|
||||
'@typescript-eslint/no-unused-vars': [
|
||||
error,
|
||||
{ ignoreRestSiblings: true, varsIgnorePattern: '^_' },
|
||||
],
|
||||
'@typescript-eslint/no-unused-vars': off,
|
||||
'@typescript-eslint/no-use-before-define': off,
|
||||
'@typescript-eslint/no-var-requires': off,
|
||||
'@typescript-eslint/restrict-template-expressions': off,
|
||||
|
@ -1,6 +1,7 @@
|
||||
import type { Rule } from 'eslint';
|
||||
import type { ESLintUtils } from '@typescript-eslint/utils';
|
||||
|
||||
import noEmptyObjectLiteral from './no-empty-object-literal';
|
||||
import noImportDot from './no-import-dot';
|
||||
import restrictTemplateExpressions from './restrict-template-expressions';
|
||||
|
||||
@ -8,6 +9,7 @@ export const rules: Record<
|
||||
string,
|
||||
Rule.RuleModule | ESLintUtils.RuleModule<string, unknown[]>
|
||||
> = {
|
||||
'no-empty-object-literal': noEmptyObjectLiteral,
|
||||
'no-import-dot': noImportDot,
|
||||
'restrict-template-expressions': restrictTemplateExpressions,
|
||||
};
|
||||
|
32
src/rules/no-empty-object-literal.ts
Normal file
32
src/rules/no-empty-object-literal.ts
Normal file
@ -0,0 +1,32 @@
|
||||
import type { Rule } from 'eslint';
|
||||
|
||||
const rule: Rule.RuleModule = {
|
||||
meta: {
|
||||
type: 'problem',
|
||||
docs: {
|
||||
description:
|
||||
'Ban assignment of empty object literals `{}` and replace them with `Object.create(null)`',
|
||||
category: 'Best Practices',
|
||||
recommended: true,
|
||||
},
|
||||
fixable: 'code',
|
||||
},
|
||||
create: context => ({
|
||||
AssignmentExpression(node) {
|
||||
if (
|
||||
node.operator === '=' &&
|
||||
node.right.type === 'ObjectExpression' &&
|
||||
node.right.properties.length === 0
|
||||
) {
|
||||
context.report({
|
||||
node,
|
||||
message:
|
||||
'Assigning empty object literals are not allowed, use `Object.create(null)` instead.',
|
||||
fix: fixer => fixer.replaceText(node.right, 'Object.create(null)'),
|
||||
});
|
||||
}
|
||||
},
|
||||
}),
|
||||
};
|
||||
|
||||
export default rule;
|
Reference in New Issue
Block a user