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