Skip to content

Commit

Permalink
chore: Enable .js TypeScript checks in repo (#6483)
Browse files Browse the repository at this point in the history
## Summary

Currently .js files weren't type checked. This PR adds type-checking for
them alongside with necessary JSDoc comments.

Requires:
- #6486
- #6487
- #6485

## Test plan

🚀
  • Loading branch information
tjzel authored Sep 8, 2024
1 parent 9e5bdc1 commit 4a99693
Show file tree
Hide file tree
Showing 44 changed files with 263 additions and 14 deletions.
21 changes: 12 additions & 9 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** @type {import('eslint').ESLint.ConfigData} */
module.exports = {
root: true,
overrides: [
Expand All @@ -8,6 +9,7 @@ module.exports = {
project: true,
tsconfigRootDir: __dirname,
},
plugins: ['tsdoc'],
extends: ['plugin:@typescript-eslint/recommended-type-checked'],
rules: {
'@typescript-eslint/no-unsafe-call': 'off',
Expand Down Expand Up @@ -39,6 +41,15 @@ module.exports = {
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-duplicate-type-constituents': 'error',
'@typescript-eslint/no-shadow': 'error',
'tsdoc/syntax': 'error',
},
},
{
files: ['*.js', '*.jsx'],
plugins: ['jsdoc'],
extends: ['plugin:jsdoc/recommended'],
rules: {
'jsdoc/tag-lines': 'off',
},
},
],
Expand All @@ -51,14 +62,7 @@ module.exports = {
'plugin:import/typescript',
'plugin:react-hooks/recommended',
],
plugins: [
'react',
'react-native',
'import',
'jest',
'@typescript-eslint',
'tsdoc',
],
plugins: ['react', 'react-native', 'import', 'jest', '@typescript-eslint'],
env: {
'react-native/react-native': true,
'jest/globals': true,
Expand All @@ -81,7 +85,6 @@ module.exports = {
'no-use-before-define': 'off',
eqeqeq: 'error',
'no-unreachable': 'error',
'tsdoc/syntax': 'error',
'jest/no-disabled-tests': 'warn',
'jest/no-focused-tests': 'error',
'jest/no-identical-title': 'error',
Expand Down
1 change: 1 addition & 0 deletions .lintstagedrc-common.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** @type {import('lint-staged').Config} */
module.exports = {
'*.(js|ts|tsx)': ['yarn eslint', 'yarn prettier --write'],
};
1 change: 1 addition & 0 deletions apps/common-app/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** @type {import('eslint').ESLint.ConfigData} */
module.exports = {
root: true,
extends: ['@react-native', 'prettier', '../../.eslintrc.js'],
Expand Down
2 changes: 2 additions & 0 deletions apps/common-app/.lintstagedrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/** @type {import('lint-staged').Config} */
const commonConfig = require('../../.lintstagedrc-common.js');

/** @type {import('lint-staged').Config} */
module.exports = {
...commonConfig,
};
1 change: 1 addition & 0 deletions apps/common-app/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** @type {import('@babel/core').TransformOptions} */
module.exports = {
presets: ['module:@react-native/babel-preset'],
plugins: ['react-native-reanimated/plugin'],
Expand Down
1 change: 1 addition & 0 deletions apps/fabric-example/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** @type {import('@babel/core').TransformOptions} */
module.exports = {
presets: ['module:@react-native/babel-preset'],
plugins: [
Expand Down
5 changes: 5 additions & 0 deletions apps/fabric-example/metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ const path = require('path');

const root = path.resolve(__dirname, '../..');

/**
* Metro configuration https://reactnative.dev/docs/metro
*
* @type {import('metro-config').MetroConfig}
*/
const config = {
watchFolders: [root],
};
Expand Down
1 change: 1 addition & 0 deletions apps/fabric-example/react-native.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** @type {import('@react-native-community/cli-types').Config} */
module.exports = {
project: {
ios: {},
Expand Down
1 change: 1 addition & 0 deletions apps/macos-example/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** @type {import('@babel/core').TransformOptions} */
module.exports = {
presets: ['module:@react-native/babel-preset'],
plugins: [
Expand Down
7 changes: 7 additions & 0 deletions apps/macos-example/metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const {
} = require('react-native-reanimated/metro-config');

const path = require('path');
// @ts-expect-error
const exclusionList = require('metro-config/src/defaults/exclusionList');
const escape = require('escape-string-regexp');
const pack = require('../../packages/react-native-reanimated/package.json');
Expand All @@ -12,6 +13,11 @@ const root = path.resolve(__dirname, '../..');

const modules = [...Object.keys(pack.peerDependencies), 'react-native-macos'];

/**
* Metro configuration https://reactnative.dev/docs/metro
*
* @type {import('metro-config').MetroConfig}
*/
const config = {
projectRoot: __dirname,
watchFolders: [root],
Expand All @@ -27,6 +33,7 @@ const config = {
),

extraNodeModules: modules.reduce((acc, name) => {
// @ts-expect-error
acc[name] = path.join(__dirname, 'node_modules', name);
return acc;
}, {}),
Expand Down
1 change: 1 addition & 0 deletions apps/next-example/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** @type {import('@babel/core').TransformOptions} */
module.exports = {
presets: ['next/babel'],
plugins: [
Expand Down
1 change: 1 addition & 0 deletions apps/next-example/pages/_document.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ body {
export default class MyDocument extends Document {
static async getInitialProps({ renderPage }) {
AppRegistry.registerComponent('main', () => Main);
// @ts-expect-error
const { getStyleElement } = AppRegistry.getApplication('main');
const page = await renderPage();
const styles = [
Expand Down
3 changes: 3 additions & 0 deletions apps/next-example/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@ export default function App() {
Next example
</Text>

{/* @ts-expect-error */}
<Text style={styles.link} accessibilityRole="link" href={`/ssg`}>
SSG
</Text>

{/* @ts-expect-error */}
<Text style={styles.link} accessibilityRole="link" href={`/ssr`}>
SSR
</Text>

{/* @ts-expect-error */}
<Text style={styles.link} accessibilityRole="link" href={`/test`}>
e2e test page
</Text>
Expand Down
1 change: 1 addition & 0 deletions apps/next-example/pages/noreanimated.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default function App() {
<Text accessibilityRole="header" style={styles.text}>
Reanimated Page
</Text>
{/* @ts-expect-error */}
<Text style={styles.link} accessibilityRole="link" href="/">
Go Back
</Text>
Expand Down
1 change: 1 addition & 0 deletions apps/next-example/pages/reanimated.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default function App() {
<Animated.Text accessibilityRole="header" style={styles.text}>
Reanimated Page
</Animated.Text>
{/* @ts-expect-error */}
<Animated.Text style={styles.link} accessibilityRole="link" href="/">
Go Back
</Animated.Text>
Expand Down
3 changes: 2 additions & 1 deletion apps/next-example/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"module": "esnext",
"incremental": true,
"isolatedModules": true,
"jsx": "preserve"
"jsx": "preserve",
"noImplicitAny": false
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "**/*.js"]
}
1 change: 1 addition & 0 deletions apps/paper-example/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** @type {import('@babel/core').TransformOptions} */
module.exports = {
presets: ['module:@react-native/babel-preset'],
plugins: [
Expand Down
5 changes: 5 additions & 0 deletions apps/paper-example/metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ const path = require('path');

const root = path.resolve(__dirname, '../..');

/**
* Metro configuration https://reactnative.dev/docs/metro
*
* @type {import('metro-config').MetroConfig}
*/
const config = {
watchFolders: [root],
};
Expand Down
1 change: 1 addition & 0 deletions apps/paper-example/react-native.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** @type {import('@react-native-community/cli-types').Config} */
module.exports = {
project: {
ios: {},
Expand Down
1 change: 1 addition & 0 deletions apps/tvos-example/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** @type {import('@babel/core').TransformOptions} */
module.exports = {
presets: ['module:@react-native/babel-preset'],
plugins: [
Expand Down
1 change: 1 addition & 0 deletions apps/tvos-example/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** @type {import('jest').Config} */
module.exports = {
preset: 'react-native',
};
3 changes: 3 additions & 0 deletions apps/tvos-example/metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ const {
} = require('react-native-reanimated/metro-config');

const path = require('path');
// @ts-expect-error
const exclusionList = require('metro-config/src/defaults/exclusionList');
const escape = require('escape-string-regexp');

const root = path.resolve(__dirname, '../..');

const modules = ['react-native'];

/** @type {import('metro-config').MetroConfig} */
const config = {
projectRoot: __dirname,
watchFolders: [root],
Expand All @@ -26,6 +28,7 @@ const config = {
),

extraNodeModules: modules.reduce((acc, name) => {
// @ts-expect-error
acc[name] = path.join(__dirname, 'node_modules', name);
return acc;
}, {}),
Expand Down
1 change: 1 addition & 0 deletions apps/tvos-example/react-native.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** @type {import('@react-native-community/cli-types').Config} */
module.exports = {
dependencies: {
// Required for Expo CLI to be used with platforms (such as Apple TV) that are not supported in Expo SDK
Expand Down
2 changes: 2 additions & 0 deletions apps/web-example/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const stylexPlugin = require('@stylexjs/babel-plugin');
const rsdPlugin = require('react-strict-dom/babel');

/** @type {import('@babel/core').ConfigFunction} */
module.exports = function (api) {
const plugins = [
rsdPlugin,
Expand All @@ -22,6 +23,7 @@ module.exports = function (api) {
if (disableBabelPlugin) {
console.log('Starting Web example without Babel plugin.');
} else {
// @ts-expect-error
plugins.push('react-native-reanimated/plugin');
}

Expand Down
3 changes: 3 additions & 0 deletions apps/web-example/metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,21 @@ const config = getDefaultConfig(projectRoot);
// 1. Watch all files within the monorepo
config.watchFolders = [monorepoRoot];
// 2. Let Metro know where to resolve packages and in what order
// @ts-expect-error
config.resolver.nodeModulesPaths = [
path.resolve(projectRoot, 'node_modules'),
path.resolve(monorepoRoot, 'node_modules'),
];

const modulesToBlock = ['@react-native'];

// @ts-expect-error
config.resolver.blacklistRE = exclusionList(
modulesToBlock.map(
(m) =>
new RegExp(`^${escape(path.join(monorepoRoot, 'node_modules', m))}\\/.*$`)
)
);

// @ts-expect-error
module.exports = wrapWithReanimatedMetroConfig(config);
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
},
"devDependencies": {
"eslint": "^8.57.0",
"eslint-plugin-jsdoc": "^50.2.2",
"husky": "^9.0.11",
"lint-staged": "^15.2.2",
"prettier": "^3.3.3",
Expand Down
1 change: 1 addition & 0 deletions packages/eslint-plugin-reanimated/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** @type {import('eslint').ESLint.ConfigData} */
module.exports = {
extends: ['../../.eslintrc.js'],
ignorePatterns: ['index.js', 'types', 'public'],
Expand Down
1 change: 1 addition & 0 deletions packages/eslint-plugin-reanimated/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** @type {import('@babel/core').TransformOptions} */
module.exports = {
presets: [
[
Expand Down
1 change: 1 addition & 0 deletions packages/eslint-plugin-reanimated/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** @type {import('jest').Config} */
module.exports = {
preset: 'react-native',
modulePathIgnorePatterns: ['lib'],
Expand Down
1 change: 1 addition & 0 deletions packages/react-native-reanimated/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** @type {import('eslint').ESLint.ConfigData} */
module.exports = {
extends: ['../../.eslintrc.js'],
overrides: [
Expand Down
1 change: 1 addition & 0 deletions packages/react-native-reanimated/.lintstagedrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const commonConfig = require('../../.lintstagedrc-common.js');

/** @type {import('lint-staged').Config} */
module.exports = {
...commonConfig,
};
1 change: 1 addition & 0 deletions packages/react-native-reanimated/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** @type {import('@babel/core').TransformOptions} */
module.exports = {
presets: [
[
Expand Down
1 change: 1 addition & 0 deletions packages/react-native-reanimated/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** @type {import('jest').Config} */
module.exports = {
preset: 'react-native',
modulePathIgnorePatterns: ['lib'],
Expand Down
4 changes: 4 additions & 0 deletions packages/react-native-reanimated/metro-config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ const COLLAPSED_STACK_REGEX = new RegExp(
.join('|')
);

/**
* @param {import('metro-config').MetroConfig} config
* @returns {import('metro-config').MetroConfig}
*/
function wrapWithReanimatedMetroConfig(config) {
return {
...config,
Expand Down
1 change: 1 addition & 0 deletions packages/react-native-reanimated/mock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const Reanimated = require('./src/mock');
// @ts-expect-error
const Animated = Reanimated.default;

module.exports = {
Expand Down
1 change: 1 addition & 0 deletions packages/react-native-reanimated/plugin/.lintstagedrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const commonConfig = require('../../../.lintstagedrc-common.js');

/** @type {import('lint-staged').Config} */
module.exports = {
...commonConfig,
};
1 change: 1 addition & 0 deletions packages/react-native-reanimated/plugin/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// This file is needed for manual tests of the plugin.
const reanimatedPlugin = require('./index.js');

/** @type {import('@babel/core').TransformOptions} */
module.exports = {
plugins: [reanimatedPlugin],
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// This file is supposed to mimic the babel.config.js that the user would have
// in their project by creating a new app from template.
/** @type {import('@babel/core').TransformOptions} */
module.exports = {
presets: ['module:@react-native/babel-preset'],
};
1 change: 1 addition & 0 deletions packages/react-native-reanimated/plugin/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"outDir": "lib",
"rootDir": "src",
"declaration": false,
"noEmit": false,
},
"include": ["src"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const NOOP = () => {
// noop
};

// ts-prune-ignore-next Is this even used?
export default {
addListener: NOOP,
removeAllListeners: NOOP,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const NOOP = () => {
// noop
};

// ts-prune-ignore-next Is this even used?
export default {
configureProps: NOOP,
connectNodes: NOOP,
Expand Down
1 change: 1 addition & 0 deletions prettier.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** @type {import('prettier').Config} */
module.exports = {
plugins: ['prettier-plugin-jsdoc'],
bracketSameLine: true,
Expand Down
Loading

0 comments on commit 4a99693

Please sign in to comment.