UNPKG

3.7 kBJavaScriptView Raw
1/**
2 * Copyright 2013-2015, Facebook, Inc.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD-style license found in the
6 * LICENSE file in the root directory of this source tree. An additional grant
7 * of patent rights can be found in the PATENTS file in the same directory.
8 */
9
10// The jshint code had more globals, which may have had something to do with
11// machine-generated code. I couldn't find references with tbgs.
12//
13// Values of true mean the global may be modified. Values of false represent
14// constants.
15const globals = {
16 __DEV__: true,
17 // Haste-defined variables
18 require: true,
19 requireDynamic: true,
20 requireLazy: true,
21 // more haste variables are defined in getConfig for modules
22
23 // Workarounds for https://github.com/babel/babel-eslint/issues/130
24 // no-undef errors incorrectly on these global flow types
25 // https://fburl.com/flow-react-defs
26 ReactComponent: false,
27 ReactClass: false,
28 ReactElement: false,
29 ReactPropsCheckType: false,
30 ReactPropsChainableTypeChecker: false,
31 ReactPropTypes: false,
32 SyntheticEvent: false,
33 SyntheticClipboardEvent: false,
34 SyntheticCompositionEvent: false,
35 SyntheticInputEvent: false,
36 SyntheticUIEvent: false,
37 SyntheticFocusEvent: false,
38 SyntheticKeyboardEvent: false,
39 SyntheticMouseEvent: false,
40 SyntheticDragEvent: false,
41 SyntheticWheelEvent: false,
42 SyntheticTouchEvent: false,
43 // a bunch of types extracted from http://git.io/vOtv9
44 // there's a bunch of overlap with browser globals, so we try to avoid
45 // redefining some of those.
46 $Either: false,
47 $All: false,
48 $Tuple: false,
49 $Supertype: false,
50 $Subtype: false,
51 $Shape: false,
52 $Diff: false,
53 $Keys: false,
54 $Enum: false,
55 $Exports: false,
56 Class: false,
57 function: false,
58 Iterable: false,
59 // suppress types
60 $FlowIssue: false,
61 $FlowFixMe: false,
62 $FixMe: false,
63 // https://fburl.com/flow-core-defs
64 Iterator: false,
65 IteratorResult: false,
66 $await: false,
67 ArrayBufferView: false,
68 // https://fburl.com/flow-fb-defs
69 FbtResult: false,
70 $jsx: false,
71 FBID: false,
72 AdAccountID: false,
73 UID: false,
74 ReactNode: false,
75 Fbt: false,
76 // https://fburl.com/flow-liverail-defs
77 LRID: false,
78 // https://fburl.com/flow-powereditor-def
79 UkiAccount: false,
80 UkiAdgroup: false,
81 UkiCampaign: false,
82 UkiCampaignGroup: false,
83 // some of this maybe should be handled by the npm globals module, but it
84 // doesn't have proper WebRTC support yet
85 // https://fburl.com/flow-webrtc-defs
86 RTCConfiguration: false,
87 RTCIceServer: false,
88 RTCOfferOptions: false,
89 RTCStatsReport: false,
90 RTCStatsCallback: false,
91 RTCPeerConnection: false,
92 RTCPeerConnectionErrorCallback: false,
93 RTCSessionDescription: false,
94 RTCSessionDescriptionInit: false,
95 RTCSessionDescriptionCallback: false,
96 RTCIceCandidate: false,
97 RTCIceCandidateInit: false,
98 RTCPeerConnectionIceEvent: false,
99 RTCPeerConnectionIceEventInit: false,
100 RTCDataChannel: false,
101 RTCDataChannelInit: false,
102 RTCDataChannelEvent: false,
103 RTCDataChannelEventInit: false,
104};
105
106// This pattern will match these texts:
107// var Foo = require('Foo');
108// var Bar = require('Foo').Bar;
109// var BarFoo = require(Bar + 'Foo');
110// var {Bar, Foo} = require('Foo');
111// import type {Bar, Foo} from 'Foo';
112// Also supports 'let' and 'const'.
113const variableNamePattern = String.raw`\s*[a-zA-Z_$][a-zA-Z_$\d]*\s*`;
114const maxLenIgnorePattern = String.raw`^(?:var|let|const|import type)\s+` +
115 '{?' + variableNamePattern + '(?:,' + variableNamePattern + ')*}?' +
116 String.raw`\s*(?:=\s*require\(|from)[a-zA-Z_+./"'\s\d\-]+\)?[^;\n]*[;\n]`;
117
118
119module.exports = {
120 globals: globals,
121 maxLenIgnorePattern: maxLenIgnorePattern,
122};