shaka-player 4.0.3 → 4.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/CONTRIBUTORS +2 -0
  3. package/README.md +20 -6
  4. package/demo/index.html +0 -2
  5. package/dist/controls.css +1 -1
  6. package/dist/deps.js +3 -3
  7. package/dist/locales.js +33 -33
  8. package/dist/shaka-player.compiled.d.ts +11 -0
  9. package/dist/shaka-player.compiled.debug.d.ts +11 -0
  10. package/dist/shaka-player.compiled.debug.externs.js +48 -37
  11. package/dist/shaka-player.compiled.debug.js +141 -137
  12. package/dist/shaka-player.compiled.debug.map +4 -4
  13. package/dist/shaka-player.compiled.externs.js +48 -37
  14. package/dist/shaka-player.compiled.js +774 -772
  15. package/dist/shaka-player.compiled.map +4 -4
  16. package/dist/shaka-player.ui.d.ts +11 -0
  17. package/dist/shaka-player.ui.debug.d.ts +11 -0
  18. package/dist/shaka-player.ui.debug.externs.js +48 -37
  19. package/dist/shaka-player.ui.debug.js +153 -149
  20. package/dist/shaka-player.ui.debug.map +4 -4
  21. package/dist/shaka-player.ui.externs.js +48 -37
  22. package/dist/shaka-player.ui.js +892 -890
  23. package/dist/shaka-player.ui.map +4 -4
  24. package/docs/tutorials/upgrade.md +1 -0
  25. package/docs/tutorials/welcome.md +6 -3
  26. package/lib/dash/dash_parser.js +5 -0
  27. package/lib/hls/hls_parser.js +6 -2
  28. package/lib/media/media_source_engine.js +57 -24
  29. package/lib/media/presentation_timeline.js +24 -1
  30. package/lib/media/streaming_engine.js +3 -4
  31. package/lib/media/time_ranges_utils.js +46 -0
  32. package/lib/player.js +1 -1
  33. package/lib/polyfill/media_capabilities.js +3 -0
  34. package/lib/polyfill/videoplaybackquality.js +3 -1
  35. package/lib/util/platform.js +19 -1
  36. package/lib/util/string_utils.js +56 -14
  37. package/maintained-branches.md +15 -0
  38. package/package.json +2 -4
  39. package/test/media/drm_engine_integration.js +24 -8
  40. package/test/media/media_source_engine_integration.js +24 -10
  41. package/test/media/media_source_engine_unit.js +53 -38
  42. package/test/media/streaming_engine_unit.js +28 -27
  43. package/test/test/util/fake_media_source_engine.js +10 -9
  44. package/app-engine/README.md +0 -9
  45. package/app-engine/demo-version-index/README.md +0 -14
  46. package/app-engine/demo-version-index/app.yaml +0 -28
  47. package/app-engine/demo-version-index/generate.py +0 -164
  48. package/app-engine/demo-version-index/main.py +0 -11
  49. package/app-engine/demo-version-index/requirements.txt +0 -5
  50. package/app-engine/demo-version-index/templates/index.html +0 -114
  51. package/app-engine/shaka-player-demo/README.md +0 -18
  52. package/app-engine/shaka-player-demo/app.yaml +0 -61
  53. package/app-engine/shaka-player-demo/main.py +0 -95
  54. package/app-engine/shaka-player-demo/posters/10yo.png +0 -0
  55. package/app-engine/shaka-player-demo/posters/10yo.xcf +0 -0
  56. package/app-engine/shaka-player-demo/posters/1yo.jpg +0 -0
  57. package/app-engine/shaka-player-demo/posters/2yo.png +0 -0
  58. package/app-engine/shaka-player-demo/posters/2yo.xcf +0 -0
  59. package/app-engine/shaka-player-demo/posters/3yo.png +0 -0
  60. package/app-engine/shaka-player-demo/posters/3yo.xcf +0 -0
  61. package/app-engine/shaka-player-demo/posters/4yo.png +0 -0
  62. package/app-engine/shaka-player-demo/posters/4yo.xcf +0 -0
  63. package/app-engine/shaka-player-demo/posters/5yo.png +0 -0
  64. package/app-engine/shaka-player-demo/posters/5yo.xcf +0 -0
  65. package/app-engine/shaka-player-demo/posters/6yo.png +0 -0
  66. package/app-engine/shaka-player-demo/posters/6yo.xcf +0 -0
  67. package/app-engine/shaka-player-demo/posters/7yo.png +0 -0
  68. package/app-engine/shaka-player-demo/posters/7yo.xcf +0 -0
  69. package/app-engine/shaka-player-demo/posters/8yo.png +0 -0
  70. package/app-engine/shaka-player-demo/posters/8yo.xcf +0 -0
  71. package/app-engine/shaka-player-demo/posters/9yo.png +0 -0
  72. package/app-engine/shaka-player-demo/posters/9yo.xcf +0 -0
  73. package/app-engine/shaka-player-demo/posters/audioOnly.gif +0 -0
  74. package/app-engine/shaka-player-demo/posters/audioRickRoll.gif +0 -0
  75. package/app-engine/shaka-player-demo/posters/colorbars.gif +0 -0
  76. package/app-engine/shaka-player-demo/posters/fireworks.jpg +0 -0
  77. package/app-engine/shaka-player-demo/posters/party-hat.png +0 -0
  78. package/app-engine/shaka-player-demo/posters/sources.txt +0 -46
  79. package/app-engine/shaka-player-demo/posters/standard.png +0 -0
  80. package/app-engine/shaka-player-demo/posters/trek.jpg +0 -0
  81. package/app-engine/shaka-player-demo/posters/valentines.png +0 -0
  82. package/app-engine/shaka-player-demo/posters/zombie.jpg +0 -0
  83. package/app-engine/shaka-player-demo/posters.py +0 -110
  84. package/app-engine/shaka-player-demo/requirements.txt +0 -5
  85. package/app-engine/shaka-player-demo/time.txt +0 -1
  86. package/build/README.md +0 -127
  87. package/build/__init__.py +0 -0
  88. package/build/all.py +0 -150
  89. package/build/apps.py +0 -186
  90. package/build/build.py +0 -392
  91. package/build/check.py +0 -354
  92. package/build/checkversion.py +0 -84
  93. package/build/compiler.py +0 -513
  94. package/build/conformance.textproto +0 -335
  95. package/build/docker/Dockerfile +0 -20
  96. package/build/docker/docker-compose.yml +0 -10
  97. package/build/docs.py +0 -54
  98. package/build/eslint-plugin-shaka-rules/arg-comment-spacing.js +0 -72
  99. package/build/eslint-plugin-shaka-rules/index.js +0 -24
  100. package/build/eslint-plugin-shaka-rules/package.json +0 -7
  101. package/build/eslint-plugin-shaka-rules/private.js +0 -109
  102. package/build/gendeps.py +0 -71
  103. package/build/generateExterns.js +0 -867
  104. package/build/generateLocalizations.py +0 -262
  105. package/build/generateTsDefs.py +0 -137
  106. package/build/install-linux-prereqs.sh +0 -136
  107. package/build/license-header +0 -5
  108. package/build/misspellings.txt +0 -39
  109. package/build/pixelsChanged.js +0 -35
  110. package/build/shaka-lab.yaml +0 -161
  111. package/build/shakaBuildHelpers.py +0 -356
  112. package/build/stats.py +0 -816
  113. package/build/subprocessWindowsPatch.py +0 -103
  114. package/build/test.py +0 -541
  115. package/build/types/ads +0 -8
  116. package/build/types/cast +0 -6
  117. package/build/types/cea +0 -13
  118. package/build/types/complete +0 -9
  119. package/build/types/core +0 -108
  120. package/build/types/dash +0 -8
  121. package/build/types/hls +0 -9
  122. package/build/types/manifests +0 -5
  123. package/build/types/networking +0 -6
  124. package/build/types/offline +0 -22
  125. package/build/types/polyfill +0 -18
  126. package/build/types/text +0 -11
  127. package/build/types/ui +0 -39
  128. package/build/updateScreenshots.py +0 -85
  129. package/build/wrapper.template.js +0 -52
@@ -1,335 +0,0 @@
1
- # Copyright 2016 Google LLC
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- # Conformance requirements:
16
- # See: https://github.com/google/closure-compiler/wiki/JS-Conformance-Framework
17
-
18
- # Disallow throwing non-Error types.
19
- requirement: {
20
- type: CUSTOM
21
- java_class: "com.google.javascript.jscomp.ConformanceRules$BanThrowOfNonErrorTypes"
22
- error_message:
23
- "Throwing non-Error types or Error itself is not allowed; "
24
- "throw shaka.util.Error instead."
25
- whitelist_regexp: "test/"
26
- whitelist_regexp: "node_modules/"
27
- }
28
- requirement: {
29
- type: BANNED_CODE_PATTERN
30
- value: "function template() { throw new Error(); }"
31
- error_message:
32
- "Throwing non-Error types or Error itself is not allowed; "
33
- "throw shaka.util.Error instead."
34
- whitelist_regexp: "test/"
35
- whitelist_regexp: "node_modules/"
36
- }
37
-
38
- # Ban accessing members of unknown types.
39
- requirement: {
40
- type: CUSTOM
41
- java_class:
42
- "com.google.javascript.jscomp.ConformanceRules$"
43
- "BanUnknownTypedClassPropsReferences"
44
- error_message:
45
- "Using properties of unknown types is not allowed; add an "
46
- "explicit type to the variable."
47
- whitelist_regexp: "demo/"
48
- }
49
- requirement {
50
- type: CUSTOM
51
- java_class: "com.google.javascript.jscomp.ConformanceRules$BanUnknownThis"
52
- error_message:
53
- "Failed to infer type of \"this\"; "
54
- "please be explicit or use bind!"
55
- # Until we can get this rule updated for ES6 static methods
56
- # (https://github.com/google/closure-compiler/issues/2880):
57
- whitelist_regexp: "test/test/util/canned_idb.js"
58
- whitelist_regexp: "test/assets/assets_integration.js"
59
- }
60
-
61
- # Reject unresolved types.
62
- requirement {
63
- type: CUSTOM
64
- java_class: "com.google.javascript.jscomp.ConformanceRules$BanUnresolvedType"
65
- error_message: "Failed to resolve type!"
66
- }
67
-
68
- # Reject global variables.
69
- requirement {
70
- type: CUSTOM
71
- java_class: "com.google.javascript.jscomp.ConformanceRules$BanGlobalVars"
72
- error_message: "Global variables are not allowed!"
73
- whitelist_regexp: "demo/"
74
- whitelist_regexp: "test/"
75
- whitelist_regexp: "node_modules/"
76
- }
77
-
78
- # Disallow using "!" on nullable numbers in boolean assignment.
79
- # Note: we can't use the pattern "var b = !n" because it causes too many
80
- # false positives.
81
- requirement: {
82
- type: BANNED_CODE_PATTERN
83
- value:
84
- "/** @param {boolean} b @param {?number} n */ "
85
- "function template(b, n) { b = !n; }"
86
- error_message:
87
- "Using \"!\" on nullable numbers in boolean assignment "
88
- "is not allowed; use an explicit comparison instead."
89
- whitelist_regexp: "node_modules/"
90
- }
91
-
92
- requirement: {
93
- type: BANNED_CODE_PATTERN
94
- value:
95
- "/** @param {*} a"
96
- " @param {(number|string|boolean|null|undefined)} x */"
97
- "function template(a, x) { expect(a).toEqual(x); }"
98
- value:
99
- "/** @param {*} a"
100
- " @param {(number|string|boolean|null|undefined)} x */"
101
- "function template(a, x) { expect(a).not.toEqual(x); }"
102
- error_message: "Use expect.toBe for primitives"
103
- }
104
-
105
- requirement: {
106
- type: BANNED_CODE_PATTERN
107
- value:
108
- "/** @param {BufferSource} a */"
109
- "function template(a) { new Uint8Array(a) }"
110
- value:
111
- "/** @param {BufferSource} a */"
112
- "function template(a) { new Int8Array(a) }"
113
- value:
114
- "/** @param {BufferSource} a */"
115
- "function template(a) { new Uint8ClampedArray(a) }"
116
- value:
117
- "/** @param {BufferSource} a */"
118
- "function template(a) { new Unt16Array(a) }"
119
- value:
120
- "/** @param {BufferSource} a */"
121
- "function template(a) { new Int16Array(a) }"
122
- value:
123
- "/** @param {BufferSource} a */"
124
- "function template(a) { new Uint32Array(a) }"
125
- value:
126
- "/** @param {BufferSource} a */"
127
- "function template(a) { new Int32Array(a) }"
128
- value:
129
- "/** @param {BufferSource} a */"
130
- "function template(a) { new Float32Array(a) }"
131
- value:
132
- "/** @param {BufferSource} a */"
133
- "function template(a) { new Float64Array(a) }"
134
- error_message: "Use shaka.util.BufferUtils.view* instead."
135
- whitelist_regexp: "lib/util/buffer_utils.js"
136
- }
137
-
138
- requirement: {
139
- type: BANNED_CODE_PATTERN
140
- value: "function template () { new Date().getTime() }"
141
- error_message: "Use Date.now() instead."
142
- }
143
-
144
- # Disallow console logging.
145
- requirement: {
146
- type: BANNED_PROPERTY_CALL
147
- value: "Console.prototype.debug"
148
- value: "Console.prototype.log"
149
- value: "Console.prototype.info"
150
- value: "Console.prototype.warn"
151
- value: "Console.prototype.error"
152
- error_message:
153
- "Using \"console\" is not allowed; "
154
- "use shaka.log instead"
155
- whitelist_regexp: "demo/"
156
- whitelist_regexp: "lib/debug/log.js"
157
- whitelist_regexp: "test/test/boot.js"
158
- whitelist_regexp: "node_modules/"
159
- whitelist_regexp: "[synthetic:es6/promise/promise]"
160
- }
161
-
162
- # Disallow querySelector and querySelectorAll since they aren't supported on
163
- # Shaka Player Embedded.
164
- requirement: {
165
- type: BANNED_PROPERTY_CALL
166
- value: "Element.prototype.querySelector"
167
- value: "Document.prototype.querySelector"
168
- value: "Element.prototype.querySelectorAll"
169
- value: "Document.prototype.querySelectorAll"
170
- error_message: "Use getElementsByTagName"
171
- whitelist_regexp: "demo/"
172
- whitelist_regexp: "ui/"
173
- whitelist_regexp: "test/"
174
- whitelist_regexp: "node_modules/"
175
- }
176
-
177
- # Disallow Element.children.
178
- requirement: {
179
- type: BANNED_PROPERTY
180
- value: "Element.prototype.children"
181
- error_message:
182
- "Using \"Element.children\" is not allowed; "
183
- "use Node.childNodes instead"
184
- }
185
-
186
- requirement: {
187
- type: BANNED_PROPERTY
188
- value: "DataView.prototype.buffer"
189
- value: "TypedArray.prototype.buffer"
190
- error_message:
191
- "Using \"TypedArray.buffer\" is not safe since it doesn\'t "
192
- "handle sub-arrays"
193
- whitelist_regexp: "lib/util/buffer_utils.js"
194
- whitelist_regexp: "lib/util/object_utils.js"
195
- whitelist_regexp: "test/util/buffer_utils_unit.js"
196
- }
197
-
198
- # Disallow Element.innerHTML and outerHTML.
199
- requirement: {
200
- type: BANNED_PROPERTY
201
- value: "Element.prototype.innerHTML"
202
- value: "Element.prototype.outerHTML"
203
- error_message:
204
- "Using \"Element.innerHTML\" or \"Element.outerHTML\" is not "
205
- "allowed due to security concerns; use textContent, "
206
- "appendChild, or removeChild instead"
207
- whitelist_regexp: "test/test/util/util.js"
208
- }
209
-
210
- # Disallow DOMRect.x and y.
211
- requirement: {
212
- type: BANNED_PROPERTY
213
- value: "DOMRect.prototype.x"
214
- value: "DOMRect.prototype.y"
215
- error_message:
216
- "DOMRect \"x\" and \"y\" are not supported on legacy Edge; "
217
- "use \"left\" and \"top\" instead."
218
- # The built-in set and map polyfills trigger this ban somehow.
219
- whitelist_regexp: "synthetic:es6/"
220
- }
221
-
222
- # Disallow fdescribe.
223
- requirement: {
224
- type: BANNED_NAME
225
- value: "fdescribe"
226
- error_message: "Using \"fdescribe\" is not allowed"
227
- }
228
-
229
- # Disallow fit.
230
- requirement: {
231
- type: BANNED_NAME
232
- value: "fit"
233
- error_message: "Using \"fit\" is not allowed"
234
- whitelist_regexp: "test/player_external.js"
235
- }
236
-
237
- # Disallow setInterval.
238
- requirement: {
239
- type: BANNED_NAME
240
- value: "window.setInterval"
241
- error_message:
242
- "setInterval has several drawbacks, most of "
243
- "all difficulty canceling and surprising behavior "
244
- "when the device goes to sleep. Please use "
245
- "shaka.util.Timer instead."
246
- whitelist_regexp: "demo/"
247
- whitelist_regexp: "test/"
248
- }
249
- requirement: {
250
- type: BANNED_NAME
251
- value: "setInterval"
252
- error_message:
253
- "setInterval has several drawbacks, most of "
254
- "all difficulty canceling and surprising behavior "
255
- "when the device goes to sleep. Please use "
256
- "shaka.util.Timer instead."
257
- whitelist_regexp: "demo/"
258
- whitelist_regexp: "test/"
259
- }
260
-
261
- # Disallow setTimeout.
262
- requirement: {
263
- type: BANNED_NAME
264
- value: "window.setTimeout"
265
- error_message:
266
- "setTimeout has several drawbacks, most of "
267
- "all difficulty canceling it. Please use "
268
- "shaka.util.Timer instead."
269
- whitelist_regexp: "demo/"
270
- whitelist_regexp: "test/"
271
- whitelist_regexp: "lib/util/delayed_tick.js"
272
- }
273
- requirement: {
274
- type: BANNED_NAME
275
- value: "setTimeout"
276
- error_message:
277
- "setTimeout has several drawbacks, most of "
278
- "all difficulty canceling it. Please use "
279
- "shaka.util.Timer instead."
280
- whitelist_regexp: "demo/"
281
- whitelist_regexp: "test/"
282
- }
283
-
284
- # Disallow eval, except when testing for modern JS syntax in demo
285
- requirement: {
286
- type: BANNED_NAME
287
- value: "window.eval"
288
- error_message: "Using \"eval\" is not allowed"
289
- whitelist_regexp: "demo/demo_utils.js"
290
- whitelist_regexp: "node_modules/google-closure-library/closure/goog/base.js"
291
- whitelist_regexp: "test/util/functional_unit.js"
292
- }
293
- requirement: {
294
- type: BANNED_NAME
295
- value: "eval"
296
- error_message: "Using \"eval\" is not allowed"
297
- whitelist_regexp: "demo/demo_utils.js"
298
- whitelist_regexp: "node_modules/google-closure-library/closure/goog/base.js"
299
- whitelist_regexp: "test/util/functional_unit.js"
300
- }
301
-
302
- # Disallow ES6 methods.
303
- requirement: {
304
- type: BANNED_PROPERTY
305
- value: "ArrayBuffer.prototype.slice"
306
- error_message:
307
- "ArrayBuffer.slice is not allowed because it "
308
- "is not supported on Tizen 2016"
309
- }
310
-
311
- # Disallow the general use of fetch, which is not available on all supported
312
- # platforms.
313
- requirement: {
314
- type: BANNED_NAME_CALL
315
- value: "fetch"
316
- value: "window.fetch"
317
- error_message:
318
- "Using \"fetch\" directly is not allowed; "
319
- "use shaka.test.Util.fetch or NetworkingEngine.request "
320
- "instead."
321
- whitelist_regexp: "lib/net/http_fetch_plugin.js"
322
- }
323
-
324
- # Disallow the use of generators, which are a major performance issue. See
325
- # https://github.com/shaka-project/shaka-player/issues/4062#issuecomment-1079428268
326
- requirement: {
327
- type: BANNED_CODE_PATTERN
328
- value:
329
- "/** @param {*} x */ "
330
- "function *template(x) { yield x; }"
331
- error_message:
332
- "ES6 generators are a major performance issue! Find another solution. "
333
- "See also https://bit.ly/3wAsoj5"
334
- whitelist_regexp: "node_modules/"
335
- }
@@ -1,20 +0,0 @@
1
- # Alpine was chosen by providing a node container less than 100mb
2
- FROM node:17.7.1-alpine3.15
3
-
4
- WORKDIR /usr/src/app
5
-
6
- # Install dependencies
7
- RUN apk add --update --no-cache openssh git python3 openjdk11-jre-headless
8
- RUN ln -sf python3 /usr/bin/python
9
-
10
- # Change to non-root user
11
- USER node
12
-
13
- # Prevent proxy timeout error (very slow connections)
14
- RUN npm config set fetch-retry-mintimeout 20000
15
- RUN npm config set fetch-retry-maxtimeout 120000
16
- RUN npm config rm proxy
17
- RUN npm config rm https-proxy
18
-
19
- # Run compilation
20
- CMD [ "python", "build/all.py" ]
@@ -1,10 +0,0 @@
1
- version: '3'
2
-
3
- services:
4
- shaka-compiler:
5
- build: ./
6
- container_name: shaka-compiler
7
- volumes:
8
- - ../../:/usr/src/app
9
-
10
- # Others services can be added here
package/build/docs.py DELETED
@@ -1,54 +0,0 @@
1
- #!/usr/bin/env python
2
- #
3
- # Copyright 2016 Google LLC
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
-
17
- """Builds the documentation from the source code.
18
-
19
- This deletes the old documentation first.
20
- """
21
-
22
- import argparse
23
- import logging
24
- import os
25
-
26
- import compiler
27
- import shakaBuildHelpers
28
-
29
-
30
- def main(args):
31
- """Builds the source code documentation."""
32
- logging.info('Building the docs...')
33
-
34
- parser = argparse.ArgumentParser(
35
- description=__doc__,
36
- formatter_class=argparse.RawDescriptionHelpFormatter)
37
- parser.add_argument(
38
- '--force',
39
- '-f',
40
- help='Force the docs to be built, even if no files have changed.',
41
- action='store_true')
42
-
43
- parsed_args = parser.parse_args(args)
44
-
45
- base = shakaBuildHelpers.get_source_base()
46
- config_path = os.path.join(base, 'docs', 'jsdoc.conf.json')
47
- jsdoc = compiler.Jsdoc(config_path)
48
- if not jsdoc.build(parsed_args.force):
49
- return 1
50
- return 0
51
-
52
-
53
- if __name__ == '__main__':
54
- shakaBuildHelpers.run_main(main)
@@ -1,72 +0,0 @@
1
- /*! @license
2
- * Shaka Player
3
- * Copyright 2016 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
-
7
- const assert = require('assert');
8
-
9
- module.exports = {
10
- meta: {
11
- type: 'suggestion',
12
- docs: {
13
- description: 'Required spacing around argument comments',
14
- category: 'Best Practices',
15
- recommended: false,
16
- },
17
- fixable: 'code',
18
- schema: [],
19
- },
20
- create: (ctx) => {
21
- const source = ctx.getSourceCode();
22
- return {
23
- ':matches(CallExpression, NewExpression)': (node) => {
24
- for (const arg of node.arguments) {
25
- const filter = (c) => c.type == 'Block' && !c.value.includes('@');
26
- const beforeComments = source.getCommentsBefore(arg).filter(filter);
27
- if (beforeComments.length > 1) {
28
- ctx.report({
29
- node: beforeComments[0],
30
- message: 'Multiple comments around arguments',
31
- });
32
- continue;
33
- }
34
-
35
- const afterComments = source.getCommentsAfter(arg).filter(filter);
36
- if (afterComments.length > 0) {
37
- ctx.report({
38
- node: afterComments[0],
39
- message: 'Argument comment should appear before argument',
40
- fix: (fixer) => {
41
- return [
42
- fixer.remove(afterComments[0]),
43
- fixer.insertTextBefore(
44
- arg, '/*' + afterComments[0].value + '*/ '),
45
- ];
46
- },
47
- });
48
- continue;
49
- }
50
-
51
- const comment = beforeComments.pop();
52
- if (!comment) {
53
- continue;
54
- }
55
-
56
- if (!/ \w+= /.exec(comment.value)) {
57
- ctx.report({
58
- node: comment,
59
- message: 'Bad spacing for argument comment',
60
- fix: (fixer) => {
61
- const newComment =
62
- comment.value.replace(/\W*(\w+).*/, ' $1= ');
63
- return fixer.replaceText(comment, '/*' + newComment + '*/');
64
- },
65
- });
66
- }
67
- }
68
- },
69
- };
70
- },
71
- };
72
-
@@ -1,24 +0,0 @@
1
- /*! @license
2
- * Shaka Player
3
- * Copyright 2016 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
-
7
- module.exports = {
8
- rules: {},
9
- configs: {
10
- config: {
11
- plugins: ['shaka-rules'],
12
- rules: {},
13
- },
14
- },
15
- };
16
-
17
- const RULES = [
18
- 'arg-comment-spacing',
19
- 'private',
20
- ];
21
- for (const rule of RULES) {
22
- module.exports.rules[rule] = require('./' + rule);
23
- module.exports.configs.config.rules['shaka-rules/' + rule] = 'error';
24
- }
@@ -1,7 +0,0 @@
1
- {
2
- "name": "eslint-plugin-shaka-rules",
3
- "description": "Extra eslint rules for Shaka Player",
4
- "version": "0.0.1",
5
- "main": "index.js",
6
- "private": true
7
- }
@@ -1,109 +0,0 @@
1
- /*! @license
2
- * Shaka Player
3
- * Copyright 2016 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
-
7
- const assert = require('assert');
8
-
9
- module.exports = {
10
- meta: {
11
- type: 'suggestion',
12
- docs: {
13
- description: 'Require correct naming of @private members',
14
- category: 'Best Practices',
15
- recommended: false,
16
- },
17
- fixable: 'code',
18
- schema: [],
19
- },
20
- create: (ctx) => {
21
- const fixComment = (comment, addPrivate) => {
22
- // The "value" field contains the *body* of the comment; so it will look
23
- // like '* foo\n * bar\n '. This return value needs to be the
24
- // code to inject, so we need to add the /* and */ back.
25
- assert.equal(comment.type, 'Block');
26
- assert(comment.value.startsWith('*'));
27
- let lines = comment.value.split('\n');
28
- const firstIndent = ' '.repeat(comment.loc.start.column);
29
- const prefix = firstIndent + ' * ';
30
-
31
- if (lines.length == 1) {
32
- if (addPrivate) {
33
- // /** Foobar */
34
- // =>
35
- // /**
36
- // * Foobar
37
- // * @private
38
- // */
39
- const body = lines[0].substr(1).trim();
40
- return '/**\n' + prefix + body + '\n' + prefix + '@private\n' +
41
- firstIndent + ' */';
42
- } else {
43
- // /** @override @private */
44
- // =>
45
- // /** @override */
46
- return '/** ' + lines[0].substr(1).replace('@private', '').trim() +
47
- ' */';
48
- }
49
- }
50
-
51
- if (addPrivate) {
52
- lines.splice(lines.length - 1, 0, prefix + '@private');
53
- } else {
54
- lines = lines.filter((line) => {
55
- if (line.includes('@private')) {
56
- // Assert the @private is on its own line.
57
- assert(line.startsWith(prefix));
58
- assert.equal(
59
- line.substr(prefix.length).replace('@private', '').trim(), '');
60
- return false;
61
- }
62
- return true;
63
- });
64
- }
65
- return '/*' + lines.join('\n') + '*/';
66
- };
67
-
68
- const source = ctx.getSourceCode();
69
- return {
70
- 'ClassBody > MethodDefinition': (node) => {
71
- const comment = source.getCommentsBefore(node).pop();
72
- const nameIsPrivate = node.key.name && node.key.name.endsWith('_');
73
- if (!comment) {
74
- if (nameIsPrivate) {
75
- ctx.report({
76
- node: node,
77
- message: 'Missing @private annotation on private member@',
78
- fix: (fixer) => {
79
- const indent = ' '.repeat(node.loc.start.column);
80
- return fixer.insertTextBefore(
81
- node, '/** @private */\n' + indent);
82
- },
83
- });
84
- }
85
- return;
86
- }
87
-
88
- const docHasPrivate = comment.value.includes('@private');
89
- if (nameIsPrivate && !docHasPrivate) {
90
- ctx.report({
91
- node: node,
92
- message: 'Missing @private annotation on private member',
93
- fix: (fixer) => {
94
- return fixer.replaceText(comment, fixComment(comment, true));
95
- },
96
- });
97
- } else if (!nameIsPrivate && docHasPrivate) {
98
- ctx.report({
99
- node: node,
100
- message: 'Invalid name for private member',
101
- fix: (fixer) => {
102
- return fixer.replaceText(comment, fixComment(comment, false));
103
- },
104
- });
105
- }
106
- },
107
- };
108
- },
109
- };