-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RN: Replace
error-subclass-name
with require-extends-error
ESLint…
… Rule Summary: Removes the `error-subclass-name` ESLint rule from `react-native/eslint-plugin`, and implements a new `require-extends-error` ESLint rule inside the React Native repository. This rule was only intended to be used for internal development of React Native. This will change `react-native/eslint-plugin` to no longer provide the `error-subclass-name` rule. NOTE: One behavior difference here is that I also implemented the desired behavior of checking classes that extend `Library.SomeError`. Changelog: [General][Removed] - `react-native/eslint-plugin` no longer provides the `error-subclass-name` rule. Reviewed By: lunaleaps Differential Revision: D39858882 fbshipit-source-id: 27b53216d77a15b3425bd9669dbc9d954c1c61da
- Loading branch information
1 parent
1ec69b1
commit 4f83498
Showing
7 changed files
with
261 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 0 additions & 100 deletions
100
packages/eslint-plugin-react-native-community/__tests__/error-subclass-name-test.js
This file was deleted.
Oops, something went wrong.
66 changes: 0 additions & 66 deletions
66
packages/eslint-plugin-react-native-community/error-subclass-name.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
151 changes: 151 additions & 0 deletions
151
tools/eslint/rules/__tests__/require-extends-error-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const rule = require('../require-extends-error.js'); | ||
const {RuleTester} = require('eslint'); | ||
|
||
const ruleTester = new RuleTester({ | ||
parser: require.resolve('hermes-eslint'), | ||
parserOptions: { | ||
ecmaVersion: 6, | ||
sourceType: 'module', | ||
}, | ||
}); | ||
|
||
ruleTester.run('functions', rule, { | ||
valid: [ | ||
{ | ||
code: `(function () {});`, | ||
}, | ||
{ | ||
code: `function xError() {}`, | ||
}, | ||
], | ||
invalid: [ | ||
{ | ||
code: 'function XError() {}', | ||
errors: [{messageId: 'errorFunction', data: {name: 'XError'}}], | ||
}, | ||
{ | ||
code: '(function XError() {});', | ||
errors: [{messageId: 'errorFunction', data: {name: 'XError'}}], | ||
}, | ||
], | ||
}); | ||
|
||
ruleTester.run('classes', rule, { | ||
valid: [ | ||
{ | ||
code: `(class {});`, | ||
}, | ||
{ | ||
code: `(class extends Y {});`, | ||
}, | ||
{ | ||
code: `class X extends Y {}`, | ||
}, | ||
{ | ||
code: `(class X extends Y {});`, | ||
}, | ||
{ | ||
code: `class XError extends Error {}`, | ||
}, | ||
{ | ||
code: `(class XError extends Error {});`, | ||
}, | ||
{ | ||
code: `class XError extends YError {}`, | ||
}, | ||
{ | ||
code: `(class XError extends YError {});`, | ||
}, | ||
{ | ||
code: `class XError extends Y.Error {}`, | ||
}, | ||
{ | ||
code: `(class XError extends Y.Error {});`, | ||
}, | ||
{ | ||
code: `class XError extends Y.Z.Error {}`, | ||
}, | ||
{ | ||
code: `(class XError extends Y.Z.Error {});`, | ||
}, | ||
], | ||
invalid: [ | ||
{ | ||
code: `class XError {}`, | ||
errors: [{messageId: 'errorClass', data: {name: 'XError'}}], | ||
}, | ||
{ | ||
code: `(class XError {});`, | ||
errors: [{messageId: 'errorClass', data: {name: 'XError'}}], | ||
}, | ||
{ | ||
code: `class XError extends Y {}`, | ||
errors: [{messageId: 'errorClass', data: {name: 'XError'}}], | ||
}, | ||
{ | ||
code: `(class XError extends Y {});`, | ||
errors: [{messageId: 'errorClass', data: {name: 'XError'}}], | ||
}, | ||
{ | ||
code: `class XError extends Y.Z {}`, | ||
errors: [{messageId: 'errorClass', data: {name: 'XError'}}], | ||
}, | ||
{ | ||
code: `(class XError extends Y.Z {});`, | ||
errors: [{messageId: 'errorClass', data: {name: 'XError'}}], | ||
}, | ||
], | ||
}); | ||
|
||
ruleTester.run('superclasses', rule, { | ||
valid: [], | ||
invalid: [ | ||
{ | ||
code: `(class extends Error {});`, | ||
errors: [{messageId: 'errorSuperClassMissingName'}], | ||
}, | ||
{ | ||
code: `class X extends Error {}`, | ||
errors: [{messageId: 'errorSuperClass', data: {name: 'X'}}], | ||
}, | ||
{ | ||
code: `(class X extends Error {});`, | ||
errors: [{messageId: 'errorSuperClass', data: {name: 'X'}}], | ||
}, | ||
{ | ||
code: `class X extends YError {}`, | ||
errors: [{messageId: 'errorSuperClass', data: {name: 'X'}}], | ||
}, | ||
{ | ||
code: `(class X extends YError {});`, | ||
errors: [{messageId: 'errorSuperClass', data: {name: 'X'}}], | ||
}, | ||
{ | ||
code: `class X extends Y.Error {}`, | ||
errors: [{messageId: 'errorSuperClass', data: {name: 'X'}}], | ||
}, | ||
{ | ||
code: `(class X extends Y.Error {});`, | ||
errors: [{messageId: 'errorSuperClass', data: {name: 'X'}}], | ||
}, | ||
{ | ||
code: `class X extends Y.Z.Error {}`, | ||
errors: [{messageId: 'errorSuperClass', data: {name: 'X'}}], | ||
}, | ||
{ | ||
code: `(class X extends Y.Z.Error {});`, | ||
errors: [{messageId: 'errorSuperClass', data: {name: 'X'}}], | ||
}, | ||
], | ||
}); |
Oops, something went wrong.