Files
react-native/tools/eslint/rules/__tests__/react-native-manifest-test.js
Tim YungandFacebook GitHub Bot ffc9ff066a RN: Enforce Manifest Constraints w/ ESLint (#39064)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/39064

Creates a new lint rule that enforces the following constraints:

- `react-native/monorepo` cannot have `dependencies`.
- `react-native` cannot have `devDependencies`.

This also includes a lengthy comment in the rule definition explaining why these constraints exist, so that future contributors can make an informed decision when reconsidering these constraints.

Changelog:
[Internal]

Reviewed By: NickGerleman

Differential Revision: D48448633

fbshipit-source-id: 26b0d74b9120ddfd2a6a72bb91f86a98c8d679ef
2023-08-18 07:48:56 -07:00

92 lines
1.9 KiB
JavaScript

/**
* 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('../react-native-manifest.js');
const {RuleTester} = require('eslint');
const ruleTester = new RuleTester({
parser: require.resolve('jsonc-eslint-parser'),
});
ruleTester.run('react-native-manifest', rule, {
valid: [
{
code: JSON.stringify({
name: '@react-native/package-name',
}),
},
{
code: JSON.stringify({
name: '@react-native/package-name',
dependencies: {
dependencyA: '1.0.0',
},
devDependencies: {
dependencyB: '1.0.0',
},
}),
},
{
code: JSON.stringify({
name: '@react-native/monorepo',
devDependencies: {
dependencyB: '1.0.0',
},
}),
},
{
code: JSON.stringify({
name: 'react-native',
dependencies: {
dependencyA: '1.0.0',
},
}),
},
],
invalid: [
{
code: JSON.stringify({
name: '@react-native/monorepo',
dependencies: {
dependencyA: '1.0.0',
},
}),
errors: [
{
messageId: 'propertyDisallowed',
data: {
property: 'dependencies',
describe:
"Declare 'dependencies' in `packages/react-native/package.json`.",
},
},
],
},
{
code: JSON.stringify({
name: 'react-native',
devDependencies: {
dependencyA: '1.0.0',
},
}),
errors: [
{
messageId: 'propertyDisallowed',
data: {
property: 'devDependencies',
describe: "Declare 'devDependencies' in `<root>/package.json`.",
},
},
],
},
],
});