Skip to content

Commit e927f2c

Browse files
committed
优化ESLint
- 修复ESLint规则行号错误BUG - 修复自定义ESLint规则无效BUG - 增加行号旁显示该行ESLint警告/错误图标 - 引入eslint-plugin-userscripts规则并适配脚本猫
1 parent 3e67f01 commit e927f2c

File tree

12 files changed

+782
-86
lines changed

12 files changed

+782
-86
lines changed

eslint/compat-grant.js

Lines changed: 265 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,265 @@
1+
// Fork from eslint-plugin-userscripts
2+
// Documentation:
3+
// - Tampermonkey: https://www.tampermonkey.net/documentation.php#_grant
4+
// - Violentmonkey: https://violentmonkey.github.io/api/gm
5+
// - Greasemonkey: https://wiki.greasespot.net/Greasemonkey_Manual:API
6+
// - ScriptCat: https://docs.scriptcat.org/docs/dev/cat-api/
7+
const compatMap = {
8+
'CAT_userConfig': [
9+
{ type: 'scriptcat', versionConstraint: '>=0.11.0-beta' },
10+
],
11+
'CAT_fileStorage': [
12+
{ type: 'scriptcat', versionConstraint: '>=0.11.0' },
13+
],
14+
'GM.addElement': [
15+
{ type: 'tampermonkey', versionConstraint: '>=4.11.6113' },
16+
{ type: 'violentmonkey', versionConstraint: '>=2.13.0-beta.3' }
17+
],
18+
GM_addElement: [
19+
{ type: 'tampermonkey', versionConstraint: '>=4.11.6113' },
20+
{ type: 'violentmonkey', versionConstraint: '>=2.13.0-beta.3' }
21+
],
22+
'GM.addStyle': [
23+
{ type: 'tampermonkey', versionConstraint: '>=4.5' },
24+
{ type: 'violentmonkey', versionConstraint: '>=2.12.0' }
25+
],
26+
GM_addStyle: [
27+
{ type: 'tampermonkey', versionConstraint: '*' },
28+
{ type: 'violentmonkey', versionConstraint: '*' },
29+
{ type: 'greasemonkey', versionConstraint: '>=0.6.1.4 <4' }
30+
],
31+
'GM.addValueChangeListener': [
32+
{ type: 'tampermonkey', versionConstraint: '>=4.5' }
33+
],
34+
GM_addValueChangeListener: [
35+
{ type: 'tampermonkey', versionConstraint: '>=2.3.2607' },
36+
{ type: 'violentmonkey', versionConstraint: '>=2.12.0' }
37+
],
38+
'GM.cookie': [{ type: 'tampermonkey', versionConstraint: '>=4.8' }],
39+
GM_cookie: [{ type: 'tampermonkey', versionConstraint: '>=4.8' }],
40+
'GM.deleteValue': [
41+
{ type: 'tampermonkey', versionConstraint: '>=4.5' },
42+
{ type: 'violentmonkey', versionConstraint: '>=2.12.0' },
43+
{ type: 'greasemonkey', versionConstraint: '>=4.0' }
44+
],
45+
GM_deleteValue: [
46+
{ type: 'tampermonkey', versionConstraint: '*' },
47+
{ type: 'violentmonkey', versionConstraint: '*' },
48+
{ type: 'greasemonkey', versionConstraint: '>=0.8.20090123.1 <4' }
49+
],
50+
'GM.download': [{ type: 'tampermonkey', versionConstraint: '>=4.5' }],
51+
GM_download: [
52+
{ type: 'tampermonkey', versionConstraint: '>=3.8' },
53+
{ type: 'violentmonkey', versionConstraint: '>=2.9.5' }
54+
],
55+
'GM.getResourceText': [{ type: 'tampermonkey', versionConstraint: '>=4.5' }],
56+
GM_getResourceText: [
57+
{ type: 'tampermonkey', versionConstraint: '*' },
58+
{ type: 'violentmonkey', versionConstraint: '*' },
59+
{ type: 'greasemonkey', versionConstraint: '>=0.8.20080609.0 <4' }
60+
],
61+
'GM.getResourceURL': [
62+
{ type: 'violentmonkey', versionConstraint: '>=2.12.0 <2.13.0.10' }
63+
],
64+
GM_getResourceURL: [
65+
{ type: 'tampermonkey', versionConstraint: '*' },
66+
{ type: 'violentmonkey', versionConstraint: '*' },
67+
{ type: 'greasemonkey', versionConstraint: '>=0.8.20080609.0 <4' }
68+
],
69+
'GM.getResourceUrl': [
70+
{ type: 'tampermonkey', versionConstraint: '>=4.5' },
71+
{ type: 'violentmonkey', versionConstraint: '>=2.13.0.10' },
72+
{ type: 'greasemonkey', versionConstraint: '>=4.0' }
73+
],
74+
'GM.getTab': [{ type: 'tampermonkey', versionConstraint: '>=4.5' }],
75+
GM_getTab: [{ type: 'tampermonkey', versionConstraint: '>=4.0.10' }],
76+
'GM.getTabs': [{ type: 'tampermonkey', versionConstraint: '>=4.5' }],
77+
GM_getTabs: [{ type: 'tampermonkey', versionConstraint: '>=4.0.10' }],
78+
'GM.getValue': [
79+
{ type: 'tampermonkey', versionConstraint: '>=4.5' },
80+
{ type: 'violentmonkey', versionConstraint: '>=2.12.0' },
81+
{ type: 'greasemonkey', versionConstraint: '>=4.0' }
82+
],
83+
GM_getValue: [
84+
{ type: 'tampermonkey', versionConstraint: '*' },
85+
{ type: 'violentmonkey', versionConstraint: '*' },
86+
{ type: 'greasemonkey', versionConstraint: '>=0.3-beta <4' }
87+
],
88+
'GM.info': [
89+
{ type: 'tampermonkey', versionConstraint: '>=4.5' },
90+
{ type: 'violentmonkey', versionConstraint: '>=2.12.0' },
91+
{ type: 'greasemonkey', versionConstraint: '>=4' }
92+
],
93+
GM_info: [
94+
{ type: 'tampermonkey', versionConstraint: '>=2.4.2718' },
95+
{ type: 'violentmonkey', versionConstraint: '*' },
96+
{ type: 'greasemonkey', versionConstraint: '>=0.9.16 <4' }
97+
],
98+
'GM.listValues': [
99+
{ type: 'tampermonkey', versionConstraint: '>=4.5' },
100+
{ type: 'violentmonkey', versionConstraint: '>=2.12.0' },
101+
{ type: 'greasemonkey', versionConstraint: '>=4' }
102+
],
103+
GM_listValues: [
104+
{ type: 'tampermonkey', versionConstraint: '*' },
105+
{ type: 'violentmonkey', versionConstraint: '*' },
106+
{ type: 'greasemonkey', versionConstraint: '>=0.8.20090123.1 <4' }
107+
],
108+
'GM.log': [
109+
{ type: 'tampermonkey', versionConstraint: '>=4.5' },
110+
{ type: 'greasemonkey', versionConstraint: '>=4' }
111+
],
112+
GM_log: [
113+
{ type: 'tampermonkey', versionConstraint: '*' },
114+
{ type: 'violentmonkey', versionConstraint: '*' },
115+
{ type: 'greasemonkey', versionConstraint: '>=0.3-beta <4' }
116+
],
117+
'GM.notification': [
118+
{ type: 'tampermonkey', versionConstraint: '>=4.5' },
119+
{ type: 'violentmonkey', versionConstraint: '>=2.12.0' },
120+
{ type: 'greasemonkey', versionConstraint: '>=4' }
121+
],
122+
GM_notification: [
123+
{ type: 'tampermonkey', versionConstraint: '>=2.0.2344' },
124+
{ type: 'violentmonkey', versionConstraint: '>=2.5.0' }
125+
],
126+
'GM.openInTab': [
127+
{ type: 'tampermonkey', versionConstraint: '>=4.5' },
128+
{ type: 'violentmonkey', versionConstraint: '>=2.12.0' },
129+
{ type: 'greasemonkey', versionConstraint: '>=4' }
130+
],
131+
GM_openInTab: [
132+
{ type: 'tampermonkey', versionConstraint: '*' },
133+
{ type: 'violentmonkey', versionConstraint: '*' },
134+
{ type: 'greasemonkey', versionConstraint: '>=0.5-beta <4' }
135+
],
136+
'GM.registerMenuCommand': [
137+
{ type: 'tampermonkey', versionConstraint: '>=4.5' },
138+
{ type: 'violentmonkey', versionConstraint: '>=2.12.0' },
139+
{ type: 'greasemonkey', versionConstraint: '>=4.11' }
140+
],
141+
GM_registerMenuCommand: [
142+
{ type: 'tampermonkey', versionConstraint: '*' },
143+
{ type: 'violentmonkey', versionConstraint: '*' },
144+
{ type: 'greasemonkey', versionConstraint: '>=0.2.5 <4' }
145+
],
146+
'GM.removeValueChangeListener': [
147+
{ type: 'tampermonkey', versionConstraint: '>=4.5' }
148+
],
149+
GM_removeValueChangeListener: [
150+
{ type: 'tampermonkey', versionConstraint: '>=2.3.2607' },
151+
{ type: 'violentmonkey', versionConstraint: '>=2.12.0' }
152+
],
153+
'GM.saveTab': [{ type: 'tampermonkey', versionConstraint: '>=4.5' }],
154+
GM_saveTab: [{ type: 'tampermonkey', versionConstraint: '>=4.0.10' }],
155+
'GM.setClipboard': [
156+
{ type: 'tampermonkey', versionConstraint: '>=4.5' },
157+
{ type: 'violentmonkey', versionConstraint: '>=2.12.0' },
158+
{ type: 'greasemonkey', versionConstraint: '>=4' }
159+
],
160+
GM_setClipboard: [
161+
{ type: 'tampermonkey', versionConstraint: '>=2.6.2767' },
162+
{ type: 'violentmonkey', versionConstraint: '>=2.5.0' },
163+
{ type: 'greasemonkey', versionConstraint: '>=1.10 <4' }
164+
],
165+
'GM.setValue': [
166+
{ type: 'tampermonkey', versionConstraint: '>=4.5' },
167+
{ type: 'violentmonkey', versionConstraint: '>=2.12.0' },
168+
{ type: 'greasemonkey', versionConstraint: '>=4' }
169+
],
170+
GM_setValue: [
171+
{ type: 'tampermonkey', versionConstraint: '*' },
172+
{ type: 'violentmonkey', versionConstraint: '*' },
173+
{ type: 'greasemonkey', versionConstraint: '>=0.3-beta <4' }
174+
],
175+
'GM.unregisterMenuCommand': [
176+
{ type: 'tampermonkey', versionConstraint: '>=4.5' }
177+
],
178+
GM_unregisterMenuCommand: [
179+
{ type: 'tampermonkey', versionConstraint: '>=3.6.3737' },
180+
{ type: 'violentmonkey', versionConstraint: '>=2.9.4' }
181+
],
182+
'GM.webRequest': [{ type: 'tampermonkey', versionConstraint: '>=4.5' }],
183+
GM_webRequest: [{ type: 'tampermonkey', versionConstraint: '>=4.4' }],
184+
GM_xmlhttpRequest: [
185+
{ type: 'tampermonkey', versionConstraint: '*' },
186+
{ type: 'violentmonkey', versionConstraint: '*' },
187+
{ type: 'greasemonkey', versionConstraint: '>=0.2.5 <4' }
188+
],
189+
'GM.xmlHttpRequest': [
190+
{ type: 'tampermonkey', versionConstraint: '>=4.5' },
191+
{ type: 'violentmonkey', versionConstraint: '>=2.12.0' },
192+
{ type: 'greasemonkey', versionConstraint: '>=4.0' }
193+
],
194+
none: [
195+
{ type: 'tampermonkey', versionConstraint: '*' },
196+
{ type: 'violentmonkey', versionConstraint: '*' },
197+
{ type: 'greasemonkey', versionConstraint: '*' }
198+
],
199+
unsafeWindow: [
200+
{ type: 'tampermonkey', versionConstraint: '*' },
201+
{ type: 'violentmonkey', versionConstraint: '*' },
202+
{ type: 'greasemonkey', versionConstraint: '>=0.5-beta' }
203+
],
204+
'window.close': [
205+
{ type: 'tampermonkey', versionConstraint: '>=3.12.58' },
206+
{ type: 'violentmonkey', versionConstraint: '>=2.6.2' }
207+
],
208+
'window.focus': [
209+
{ type: 'tampermonkey', versionConstraint: '>=3.12.58' },
210+
{ type: 'violentmonkey', versionConstraint: '>=2.12.10' }
211+
],
212+
'window.onurlchange': [{ type: 'tampermonkey', versionConstraint: '>=4.11' }]
213+
};
214+
215+
const gmPolyfillOverride = {
216+
GM_addStyle: 'ignore',
217+
GM_registerMenuCommand: 'ignore',
218+
GM_getResourceText: {
219+
deps: ['GM.getResourceUrl', 'GM.log']
220+
},
221+
'GM.log': 'ignore',
222+
'GM.info': {
223+
deps: ['GM_info']
224+
},
225+
'GM.addStyle': {
226+
deps: ['GM_addStyle']
227+
},
228+
'GM.deleteValue': {
229+
deps: ['GM_deleteValue']
230+
},
231+
'GM.getResourceUrl': {
232+
deps: ['GM_getResourceURL']
233+
},
234+
'GM.getValue': {
235+
deps: ['GM_getValue']
236+
},
237+
'GM.listValues': {
238+
deps: ['GM_listValues']
239+
},
240+
'GM.notification': {
241+
deps: ['GM_notification']
242+
},
243+
'GM.openInTab': {
244+
deps: ['GM_openInTab']
245+
},
246+
'GM.registerMenuCommand': {
247+
deps: ['GM_registerMenuCommand']
248+
},
249+
'GM.setClipboard': {
250+
deps: ['GM_setClipboard']
251+
},
252+
'GM.setValue': {
253+
deps: ['GM_setValue']
254+
},
255+
'GM.xmlHttpRequest': {
256+
deps: ['GM_xmlhttpRequest']
257+
},
258+
'GM.getResourceText': {
259+
deps: ['GM_getResourceText']
260+
}
261+
262+
};
263+
264+
module.exports.compatMap = compatMap;
265+
module.exports.gmPolyfillOverride = gmPolyfillOverride;

0 commit comments

Comments
 (0)