Skip to content

Commit 2fa7496

Browse files
chore: lint TypeScript output script
1 parent 973ee86 commit 2fa7496

File tree

2 files changed

+113
-1
lines changed

2 files changed

+113
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
],
3535
"scripts": {
3636
"typescript": "tsc --noEmit",
37-
"lint": "eslint --ext '.js,.ts,.tsx' . --fix",
37+
"lint": "eslint --ext '.js,.ts,.tsx' . --fix && node ./scripts/typescript-output-lint",
3838
"test": "jest",
3939
"prepare": "bob build && node ./scripts/generate-mappings.js",
4040
"release": "release-it",

scripts/typescript-output-lint.js

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
const { promises: fs } = require('fs');
2+
const path = require('path');
3+
4+
const root = path.resolve(__dirname, '..');
5+
const output = path.join(root, 'lib', 'typescript');
6+
7+
/**
8+
* List of React Native props not used by React Native Paper.
9+
* Feel free to delete props from this list when
10+
* a React Native Paper has defined one with the same name.
11+
* This script was originally created to detect if
12+
* TypeScript has exported a large union of props from ViewProps.
13+
*/
14+
const unusedViewProps = [
15+
'nativeID',
16+
'accessibilityActions',
17+
'accessibilityRole',
18+
'accessibilityValue',
19+
'onAccessibilityAction',
20+
'accessibilityLabelledBy',
21+
'accessibilityLiveRegion',
22+
'accessibilityLanguage',
23+
'accessibilityViewIsModal',
24+
'onAccessibilityEscape',
25+
'onAccessibilityTap',
26+
'onMagicTap',
27+
'accessibilityIgnoresInvertColors',
28+
'hitSlop',
29+
'removeClippedSubviews',
30+
'collapsable',
31+
'needsOffscreenAlphaCompositing',
32+
'renderToHardwareTextureAndroid',
33+
'shouldRasterizeIOS',
34+
'isTVSelectable',
35+
'hasTVPreferredFocus',
36+
'tvParallaxProperties',
37+
'tvParallaxShiftDistanceX',
38+
'tvParallaxShiftDistanceY',
39+
'tvParallaxTiltAngle',
40+
'tvParallaxMagnification',
41+
'onStartShouldSetResponder',
42+
'onMoveShouldSetResponder',
43+
'onResponderEnd',
44+
'onResponderGrant',
45+
'onResponderReject',
46+
'onResponderMove',
47+
'onResponderRelease',
48+
'onResponderStart',
49+
'onResponderTerminationRequest',
50+
'onResponderTerminate',
51+
'onStartShouldSetResponderCapture',
52+
'onMoveShouldSetResponderCapture',
53+
'onTouchStart',
54+
'onTouchMove',
55+
'onTouchEnd',
56+
'onTouchCancel',
57+
'onTouchEndCapture',
58+
'onPointerEnter',
59+
'onPointerEnterCapture',
60+
'onPointerLeave',
61+
'onPointerLeaveCapture',
62+
'onPointerMove',
63+
'onPointerMoveCapture',
64+
'onPointerCancel',
65+
'onPointerCancelCapture',
66+
'onPointerDown',
67+
'onPointerDownCapture',
68+
'onPointerUp',
69+
'onPointerUpCapture',
70+
'onHoverIn',
71+
'onHoverOut',
72+
'cancelable',
73+
'delayHoverIn',
74+
'delayHoverOut',
75+
'pressRetentionOffset',
76+
'android_disableSound',
77+
'android_ripple',
78+
'testOnly_pressed',
79+
'unstable_pressDelay',
80+
];
81+
82+
async function* getFiles(directory) {
83+
const entries = await fs.readdir(directory, { withFileTypes: true });
84+
for (const entry of entries) {
85+
const res = path.resolve(directory, entry.name);
86+
if (entry.isDirectory()) {
87+
yield* getFiles(res);
88+
} else {
89+
yield res;
90+
}
91+
}
92+
}
93+
94+
async function main() {
95+
for await (const file of getFiles(output)) {
96+
const content = await fs.readFile(file);
97+
for (const prop of unusedViewProps) {
98+
if (content.includes(prop)) {
99+
throw new Error(
100+
`Found text '${prop}' in '${file}'. Please use the wrapped 'fetchRef' in 'src/utils/fetchRef.ts', export some return types, or modify 'scripts/typescript-output-lint.js'`
101+
);
102+
}
103+
}
104+
}
105+
106+
console.log('✅ No React Native props mentioned in TypeScript files');
107+
}
108+
109+
main().catch((reason) => {
110+
console.error(reason);
111+
process.exit(1);
112+
});

0 commit comments

Comments
 (0)