Skip to content

Commit

Permalink
chore: Upgrade eslint
Browse files Browse the repository at this point in the history
The new eslint found many style errors which have now been corrected.

It also complains a lot about atomic update issues that do not seem to
exist, so that rule has been disabled.

This upgrade will allow us to adopt eslint's "id-denylist" instead of
the older "id-blacklist" rule, the name of which violates new Google
guidelines about respectful language.

Bug: 178203011

Change-Id: Ia65581b96e4dd1331f720fa396183dca020b9caf
  • Loading branch information
joeyparrish committed Feb 1, 2021
1 parent 0845843 commit 7544670
Show file tree
Hide file tree
Showing 16 changed files with 82 additions and 96 deletions.
15 changes: 14 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ module.exports = {
'no-empty': ['error', {'allowEmptyCatch': true}],
'no-misleading-character-class': 'error',
'no-template-curly-in-string': 'error',
'require-atomic-updates': 'error',
// TODO: Try to re-enable this if possible. Right now, it produces way too
// many false-positives with eslint 7. It worked well enough in eslint 5.
// 'require-atomic-updates': 'error',
// }}}

// "Best practices" rules: {{{
Expand Down Expand Up @@ -292,5 +294,16 @@ module.exports = {
'test/**/*.js',
],
},
{
'rules': {
// Externs naturally redeclare things eslint knows about.
'no-redeclare': 'off',
},
'files': [
'ui/externs/*.js',
'externs/**/*.js',
'test/test/externs/*.js',
],
},
],
};
2 changes: 1 addition & 1 deletion lib/cast/cast_proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ shaka.cast.CastProxy = class extends shaka.util.FakeEventTarget {
configurable: false,
enumerable: true,
get: () => this.videoProxyGet_(k),
set: (value) => this.videoProxySet_(k, value),
set: (value) => { this.videoProxySet_(k, value); },
});
}

Expand Down
7 changes: 2 additions & 5 deletions lib/dependencies/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ shaka.dependencies = class {
/** @return {?muxjs} */
static muxjs() {
return /** @type {?muxjs} */ (shaka.dependencies.dependencies_.get(
shaka.dependencies.Allowed.muxjs
));
shaka.dependencies.Allowed.muxjs));
}
};

Expand All @@ -60,6 +59,4 @@ shaka.dependencies.Allowed = {
// Add global muxjs object for backward compatibility
shaka.dependencies.dependencies_.set(
shaka.dependencies.Allowed.muxjs,
window.muxjs
);

window.muxjs);
3 changes: 1 addition & 2 deletions lib/media/drm_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -752,8 +752,7 @@ shaka.media.DrmEngine = class {
if (info.initData && info.initData.length) {
config.initDataTypes = [
...new Set(
info.initData.map((initData) => initData.initDataType)
),
info.initData.map((initData) => initData.initDataType)),
];
}
if (info.distinctiveIdentifierRequired) {
Expand Down
3 changes: 1 addition & 2 deletions lib/offline/indexeddb/base_storage_cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,7 @@ shaka.offline.indexeddb.BaseStorageCell = class {
shaka.util.Error.Severity.CRITICAL,
shaka.util.Error.Category.STORAGE,
shaka.util.Error.Code.KEY_NOT_FOUND,
'Could not find values for ' + missing
);
'Could not find values for ' + missing);
}

return keys.map((key) => values[key]);
Expand Down
3 changes: 1 addition & 2 deletions lib/offline/indexeddb/db_connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ shaka.offline.indexeddb.DBConnection = class {
// Once the operation is done (regardless of outcome) stop tracking it.
operation.promise().then(
() => this.stopTracking_(operation),
() => this.stopTracking_(operation)
);
() => this.stopTracking_(operation));

return operation;
}
Expand Down
1 change: 1 addition & 0 deletions lib/util/multi_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ shaka.util.MultiMap = class {
* @param {T} value
*/
push(key, value) {
// eslint-disable-next-line no-prototype-builtins
if (this.map_.hasOwnProperty(key)) {
this.map_[key].push(value);
} else {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"core-js": "^3.6.5",
"dialog-polyfill": "^0.5.0",
"es6-promise-polyfill": "^1.2.0",
"eslint": "^5.16.0",
"eslint": "^7.18.0",
"eslint-config-google": "^0.13.0",
"eslint-plugin-shaka-rules": "file:./build/eslint-plugin-shaka-rules",
"esprima": "^4.0.1",
Expand Down
16 changes: 7 additions & 9 deletions test/cast/cast_receiver_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -1174,15 +1174,13 @@ filterDescribe('CastReceiver', castReceiverSupport, () => {
expectedMedia.metadata = metadata;
}

expect(mockGenericMessageBus.messages[0]).toEqual(
{
requestId: 0,
type: 'MEDIA_STATUS',
status: [jasmine.objectContaining({
media: expectedMedia,
})],
}
);
expect(mockGenericMessageBus.messages[0]).toEqual({
requestId: 0,
type: 'MEDIA_STATUS',
status: [jasmine.objectContaining({
media: expectedMedia,
})],
});
mockGenericMessageBus.messages.shift();
}
});
40 changes: 14 additions & 26 deletions test/dash/dash_parser_content_protection_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,13 @@ describe('DashParser ContentProtection', () => {
'</ContentProtection>',
], []);

const initData = buildInitData(
['bm8gaHVtYW4gY2FuIHJlYWQgYmFzZTY0IGRpcmVjdGx5'], // PSSHs
['deadbeeffeedbaadf00d000008675309']); // key ID for init data
const expected = buildExpectedManifest([
buildDrmInfo('com.widevine.alpha',
['deadbeeffeedbaadf00d000008675309'], // key ID
buildInitData(
['bm8gaHVtYW4gY2FuIHJlYWQgYmFzZTY0IGRpcmVjdGx5'], // PSSHs
['deadbeeffeedbaadf00d000008675309'] // key ID for init data
)
),
initData),
]);
await testDashParser(source, expected);
});
Expand Down Expand Up @@ -344,12 +343,10 @@ describe('DashParser ContentProtection', () => {
const expected = buildExpectedManifest([
buildDrmInfo('com.widevine.alpha',
[], // key IDs
buildInitData(['ZmFrZSBXaWRldmluZSBQU1NI'])
),
buildInitData(['ZmFrZSBXaWRldmluZSBQU1NI'])),
buildDrmInfo('com.microsoft.playready',
[], // key IDs
buildInitData(['bm8gaHVtYW4gY2FuIHJlYWQgYmFzZTY0IGRpcmVjdGx5'])
),
buildInitData(['bm8gaHVtYW4gY2FuIHJlYWQgYmFzZTY0IGRpcmVjdGx5'])),
]);
await testDashParser(source, expected);
});
Expand All @@ -367,8 +364,7 @@ describe('DashParser ContentProtection', () => {
[], // key IDs
buildInitData([
'AAAAKXBzc2gAAAAAmgTweZhAQoarkuZb4IhflQAAAAlQbGF5cmVhZHk=',
])
),
])),
]);
await testDashParser(source, expected);
});
Expand All @@ -385,8 +381,7 @@ describe('DashParser ContentProtection', () => {
const expected = buildExpectedManifest([
buildDrmInfo('com.microsoft.playready',
[], // key IDs
buildInitData(['bm8gaHVtYW4gY2FuIHJlYWQgYmFzZTY0IGRpcmVjdGx5'])
),
buildInitData(['bm8gaHVtYW4gY2FuIHJlYWQgYmFzZTY0IGRpcmVjdGx5'])),
]);
await testDashParser(source, expected);
});
Expand Down Expand Up @@ -433,8 +428,7 @@ describe('DashParser ContentProtection', () => {
]);
const expected = buildExpectedManifest(
/** @type {!Array.<shaka.extern.DrmInfo>} */(drmInfos),
[], // key IDs
);
[]); // key IDs
await testDashParser(source, expected, /* ignoreDrmInfo= */ true);
});

Expand Down Expand Up @@ -484,12 +478,10 @@ describe('DashParser ContentProtection', () => {
const expected = buildExpectedManifest([
buildDrmInfo('com.widevine.alpha',
[], // key IDs
buildInitData(['b25lIGhlYWRlciB0byBydWxlIHRoZW0gYWxs'])
),
buildInitData(['b25lIGhlYWRlciB0byBydWxlIHRoZW0gYWxs'])),
buildDrmInfo('com.microsoft.playready',
[], // key IDs
buildInitData(['b25lIGhlYWRlciB0byBydWxlIHRoZW0gYWxs'])
),
buildInitData(['b25lIGhlYWRlciB0byBydWxlIHRoZW0gYWxs'])),
]);
await testDashParser(source, expected);
});
Expand All @@ -514,13 +506,10 @@ describe('DashParser ContentProtection', () => {
buildDrmInfo('com.widevine.alpha',
[], // key IDs
buildInitData(
['VGltZSBpcyBhbiBpbGx1c2lvbi4gTHVuY2h0aW1lIGRvdWJseSBzby4='],
)
),
['VGltZSBpcyBhbiBpbGx1c2lvbi4gTHVuY2h0aW1lIGRvdWJseSBzby4='])),
buildDrmInfo('com.microsoft.playready',
[], // key IDs
buildInitData(['b25lIGhlYWRlciB0byBydWxlIHRoZW0gYWxs']),
),
buildInitData(['b25lIGhlYWRlciB0byBydWxlIHRoZW0gYWxs'])),
]);
await testDashParser(source, expected);
});
Expand Down Expand Up @@ -708,8 +697,7 @@ describe('DashParser ContentProtection', () => {
const expected = buildExpectedManifest([
buildDrmInfo('com.widevine.alpha',
[], // key IDs
buildInitData(['b25lIGhlYWRlciB0byBydWxlIHRoZW0gYWxs'])
),
buildInitData(['b25lIGhlYWRlciB0byBydWxlIHRoZW0gYWxs'])),
]);
await testDashParser(source, expected);
});
Expand Down
58 changes: 28 additions & 30 deletions test/dash/dash_parser_manifest_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,15 +380,15 @@ describe('DashParser Manifest', () => {
const stream1 = manifest.variants[0].video;
const stream2 = manifest.variants[1].video;

const expectedClosedCaptions1 = new Map(
[['CC1', shaka.util.LanguageUtils.normalize('eng')],
['CC3', shaka.util.LanguageUtils.normalize('swe')]]
);

const expectedClosedCaptions2 = new Map(
[['svc1', shaka.util.LanguageUtils.normalize('bos')],
['svc3', shaka.util.LanguageUtils.normalize('cze')]]
);
const expectedClosedCaptions1 = new Map([
['CC1', shaka.util.LanguageUtils.normalize('eng')],
['CC3', shaka.util.LanguageUtils.normalize('swe')],
]);

const expectedClosedCaptions2 = new Map([
['svc1', shaka.util.LanguageUtils.normalize('bos')],
['svc3', shaka.util.LanguageUtils.normalize('cze')],
]);
expect(stream1.closedCaptions).toEqual(expectedClosedCaptions1);
expect(stream2.closedCaptions).toEqual(expectedClosedCaptions2);
});
Expand All @@ -414,10 +414,10 @@ describe('DashParser Manifest', () => {
/** @type {shaka.extern.Manifest} */
const manifest = await parser.start('dummy://foo', playerInterface);
const stream = manifest.variants[0].video;
const expectedClosedCaptions = new Map(
[['svc1', shaka.util.LanguageUtils.normalize('eng')],
['svc3', shaka.util.LanguageUtils.normalize('swe')]]
);
const expectedClosedCaptions = new Map([
['svc1', shaka.util.LanguageUtils.normalize('eng')],
['svc3', shaka.util.LanguageUtils.normalize('swe')],
]);
expect(stream.closedCaptions).toEqual(expectedClosedCaptions);
});

Expand All @@ -442,10 +442,10 @@ describe('DashParser Manifest', () => {
/** @type {shaka.extern.Manifest} */
const manifest = await parser.start('dummy://foo', playerInterface);
const stream = manifest.variants[0].video;
const expectedClosedCaptions = new Map(
[['svc1', shaka.util.LanguageUtils.normalize('eng')],
['svc2', shaka.util.LanguageUtils.normalize('swe')]]
);
const expectedClosedCaptions = new Map([
['svc1', shaka.util.LanguageUtils.normalize('eng')],
['svc2', shaka.util.LanguageUtils.normalize('swe')],
]);
expect(stream.closedCaptions).toEqual(expectedClosedCaptions);
});

Expand Down Expand Up @@ -503,19 +503,17 @@ describe('DashParser Manifest', () => {
const stream1 = manifest.variants[0].video;
const stream2 = manifest.variants[1].video;

const expectedClosedCaptions1 = new Map(
[['CC1', shaka.util.LanguageUtils.normalize('eng')],
['CC3', shaka.util.LanguageUtils.normalize('swe')]]
);

const expectedClosedCaptions2 = new Map(
[
['CC1', shaka.util.LanguageUtils.normalize('eng')],
['CC2', shaka.util.LanguageUtils.normalize('swe')],
['CC3', shaka.util.LanguageUtils.normalize('fre')],
['CC4', shaka.util.LanguageUtils.normalize('pol')],
]
);
const expectedClosedCaptions1 = new Map([
['CC1', shaka.util.LanguageUtils.normalize('eng')],
['CC3', shaka.util.LanguageUtils.normalize('swe')],
]);

const expectedClosedCaptions2 = new Map([
['CC1', shaka.util.LanguageUtils.normalize('eng')],
['CC2', shaka.util.LanguageUtils.normalize('swe')],
['CC3', shaka.util.LanguageUtils.normalize('fre')],
['CC4', shaka.util.LanguageUtils.normalize('pol')],
]);

expect(stream1.closedCaptions).toEqual(expectedClosedCaptions1);
expect(stream2.closedCaptions).toEqual(expectedClosedCaptions2);
Expand Down
16 changes: 7 additions & 9 deletions test/hls/manifest_text_parser_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,15 +323,13 @@ describe('ManifestTextParser', () => {
new shaka.hls.Tag(/* id= */ 0, 'EXT-X-MEDIA-SEQUENCE', [], '1'),
],
segments: [
new shaka.hls.Segment('https://test/test.mp4',
[
new shaka.hls.Tag(
/* id= */ 2,
'EXTINF',
[new shaka.hls.Attribute('pid', '180')],
'5.99467'
),
]),
new shaka.hls.Segment('https://test/test.mp4', [
new shaka.hls.Tag(
/* id= */ 2,
'EXTINF',
[new shaka.hls.Attribute('pid', '180')],
'5.99467'),
]),
],
},

Expand Down
3 changes: 1 addition & 2 deletions test/text/lrc_text_parser_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ describe('LrcTextParser', () => {
const expected = cues.map((cue) => {
if (cue.nestedCues) {
cue.nestedCues = cue.nestedCues.map(
(nestedCue) => jasmine.objectContaining(nestedCue)
);
(nestedCue) => jasmine.objectContaining(nestedCue));
}
return jasmine.objectContaining(cue);
});
Expand Down
3 changes: 1 addition & 2 deletions test/text/srt_text_parser_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ describe('SrtTextParser', () => {
const expected = cues.map((cue) => {
if (cue.nestedCues) {
cue.nestedCues = cue.nestedCues.map(
(nestedCue) => jasmine.objectContaining(nestedCue)
);
(nestedCue) => jasmine.objectContaining(nestedCue));
}
return jasmine.objectContaining(cue);
});
Expand Down
3 changes: 1 addition & 2 deletions test/text/vtt_text_parser_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -759,8 +759,7 @@ describe('VttTextParser', () => {
const expected = cues.map((cue) => {
if (cue.nestedCues) {
cue.nestedCues = cue.nestedCues.map(
(nestedCue) => jasmine.objectContaining(nestedCue)
);
(nestedCue) => jasmine.objectContaining(nestedCue));
}
return jasmine.objectContaining(cue);
});
Expand Down
3 changes: 1 addition & 2 deletions test/ui/ui_integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,7 @@ describe('UI', () => {
languagesToButtons = mapChoicesToButtons(
/* allButtons= */ languageButtons,
/* choices= */ langsFromContent,
/* modifier= */ getNativeName
);
/* modifier= */ getNativeName);

const button = languagesToButtons.get(newLanguage);
const isChosen = button.querySelector('.shaka-chosen-item');
Expand Down

0 comments on commit 7544670

Please sign in to comment.