-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathno-deprecations.js
More file actions
188 lines (175 loc) · 6.4 KB
/
no-deprecations.js
File metadata and controls
188 lines (175 loc) · 6.4 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
"use strict";
const { createVersionValidator } = require('../utils/version-parser.js')
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
const global = {
'$': '19.0.0',
Backbone: '18.0.0',
Clipboard: '18.0.0',
ClipboardJs: '18.0.0',
DOMPurify: '18.0.0',
formatDate: '16.0.0',
getURLParameter: '16.0.0',
Handlebars: '18.0.0',
humanFileSize: '16.0.0',
initCore: '17.0.0',
jQuery: '19.0.0',
jstimezonedetect: '18.0.0',
jstz: '18.0.0',
md5: '18.0.0',
moment: '18.0.0',
oc_appconfig: '17.0.0',
oc_appswebroots: '17.0.0',
oc_capabilities: '17.0.0',
oc_config: '17.0.0',
oc_current_user: '17.0.0',
oc_debug: '17.0.0',
oc_isadmin: '17.0.0',
oc_requesttoken: '17.0.0',
oc_webroot: '17.0.0',
OCDialogs: '17.0.0',
relative_modified_date: '16.0.0',
};
const oc = {
L10n: '26.0.0',
_capabilities: '17.0.0',
addTranslations: '17.0.0',
basename: '18.0.0',
coreApps: '17.0.0',
currentUser: '19.0.0',
dirname: '18.0.0',
encodePath: '18.0.0',
fileIsBlacklisted: '17.0.0',
filePath: '19.0.0',
generateUrl: '19.0.0',
get: '19.0.0',
getCanonicalLocale: '20.0.0',
getCurrentUser: '19.0.0',
getHost: '17.0.0',
getHostName: '17.0.0',
getPort: '17.0.0',
getProtocol: '17.0.0',
getRootPath: '19.0.0',
imagePath: '19.0.0',
isSamePath: '18.0.0',
joinPaths: '18.0.0',
linkTo: '19.0.0',
linkToOCS: '19.0.0',
linkToRemote: '19.0.0',
set: '19.0.0',
webroot: '19.0.0',
};
const oca = {
Search: '20.0.0',
}
const ocp = {
Toast: '19.0.0',
}
const oc_sub = {
Util: {
formatDate: '20.0.0',
humanFileSize: '20.0.0',
relativeModifiedDate: '20.0.0',
}
};
module.exports = {
meta: {
docs: {
description: "Deprecated Nextcloud APIs",
category: "Nextcloud",
recommended: true
},
fixable: null, // or "code" or "whitespace"
schema: [
{
// We accept one option which is an object
type: "object",
properties: {
// if we should try to find an appinfo and only handle APIs removed before the max-version
parseAppInfo: {
type: "boolean"
},
// Set a Nextcloud target version, only APIs removed before that versions are checked
targetVersion: {
type: "string"
}
},
"additionalProperties": false
}
],
messages: {
deprecatedGlobal: "The global property or function {{name}} was deprecated in Nextcloud {{version}}"
}
},
create: function (context) {
const checkTargetVersion = createVersionValidator(context)
return {
MemberExpression: function (node) {
// OC.x
if (node.object.name === 'OC'
&& oc.hasOwnProperty(node.property.name)
&& checkTargetVersion(oc[node.property.name])) {
context.report(node, "The property or function OC." + node.property.name + " was deprecated in Nextcloud " + oc[node.property.name]);
}
// OCA.x
if (node.object.name === 'OCA'
&& oca.hasOwnProperty(node.property.name)
&& checkTargetVersion(oca[node.property.name])) {
context.report(node, "The property or function OCA." + node.property.name + " was deprecated in Nextcloud " + oca[node.property.name]);
}
// OCP.x
if (node.object.name === 'OCP'
&& ocp.hasOwnProperty(node.property.name)
&& checkTargetVersion(ocp[node.property.name])) {
context.report(node, "The property or function OCP." + node.property.name + " was deprecated in Nextcloud " + ocp[node.property.name]);
}
// OC.x.y
if (node.object.type === 'MemberExpression'
&& node.object.object.name === 'OC'
&& oc_sub.hasOwnProperty(node.object.property.name)
&& oc_sub[node.object.property.name].hasOwnProperty(node.property.name)) {
const version = oc_sub[node.object.property.name][node.property.name]
if (checkTargetVersion(version)) {
const prop = [
"OC",
node.object.property.name,
node.property.name,
].join('.');
const version = oc_sub[node.object.property.name][node.property.name]
context.report(node, "The property or function " + prop + " was deprecated in Nextcloud " + version);
}
}
},
Program() {
// Logic adapted from https://github.com/eslint/eslint/blob/master/lib/rules/no-restricted-globals.js
const scope = context.getScope();
const report = ref => {
const node = ref.identifier;
if (checkTargetVersion(global[node.name])) {
context.report({
node,
messageId: 'deprecatedGlobal',
data: {
name: node.name,
version: global[node.name]
},
});
}
}
// Report variables declared elsewhere (ex: variables defined as "global" by eslint)
scope.variables.forEach(variable => {
if (!variable.defs.length && global.hasOwnProperty(variable.name)) {
variable.references.forEach(report);
}
});
// Report variables not declared at all
scope.through.forEach(reference => {
if (global.hasOwnProperty(reference.identifier.name)) {
report(reference);
}
});
}
};
}
};