Skip to content

Commit

Permalink
RN: Fix sort-imports Lint Configuration (facebook#47104)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#47104

In facebook#46082, the lint configuration for `lint/sort-imports` was accidentally removed.

This has happened on more than one occasion in the past. In order to prevent this from happening again in the future, I'm also adding a Jest integration test to verify that this lint rule is enabled in the `eslintrc.js` configuration.

Changelog:
[Internal]

Reviewed By: robhogan

Differential Revision: D64547410

fbshipit-source-id: ec4f14aff140691b644189dfa3116a3d39285f80
  • Loading branch information
yungsters authored and facebook-github-bot committed Oct 18, 2024
1 parent 14bbb87 commit 892ce1b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module.exports = {
// These rules are not required with hermes-eslint
'ft-flow/define-flow-type': 0,
'ft-flow/use-flow-type': 0,
'lint/sort-imports': 1,
// flow handles this check for us, so it's not required
'no-undef': 0,
},
Expand Down
43 changes: 43 additions & 0 deletions tools/eslint/__tests__/eslintrc-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* 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.
*
* @flow strict-local
* @format
*/

// $FlowFixMe[untyped-import] - Flow lib is not configured.
import {ESLint} from 'eslint';
import path from 'path';

const REPO_DIR = path.resolve(__dirname, '..', '..', '..');

describe('react-native/.eslintrc.js', () => {
describe('lint/sort-imports', () => {
const testDirectories = [
'.',
'packages/react-native',
'packages/react-native/Libraries',
'packages/virtualized-lists',
'tools',
];
const testFilenames = ['file.js', 'file.js.flow', 'file.jsx'];

const testPaths = testDirectories.flatMap(testDirectory =>
testFilenames.map(testFilename => path.join(testDirectory, testFilename)),
);

it.each(testPaths)('checks `%s`', async testPath => {
const eslint = new ESLint({cwd: REPO_DIR});
const config = await eslint.calculateConfigForFile(testPath);
expect(config).toHaveProperty(
'rules',
expect.objectContaining({
'lint/sort-imports': expect.arrayContaining([1]),
}),
);
});
});
});

0 comments on commit 892ce1b

Please sign in to comment.