Skip to content

Commit

Permalink
Add some additional style rules.
Browse files Browse the repository at this point in the history
- Disallow mixing different types of some operators (e.g. && ||).
- Disallow useless constructors.
- Require a newline between class members.
- Require spacing around arrow functions.
- Require using the compound assignment when possible (e.g. +=).
- Check for possible errors in assignments involving "await".

Change-Id: Ib48167aea61a62b33f0b76bb869abe18398ee5b7
  • Loading branch information
TheModMaker committed May 8, 2019
1 parent 4583402 commit b87a066
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 7 deletions.
9 changes: 9 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ module.exports = {
"getter-return": "error",
"no-await-in-loop": "error",
"no-template-curly-in-string": "error",
"require-atomic-updates": "error",
// }}}

// "Best practices" rules we should be able to pass, but are not part of "eslint:recommended": {{{
Expand Down Expand Up @@ -133,6 +134,14 @@ module.exports = {

// Style rules that don't seem to be in the Google style config: {{{
"array-bracket-newline": ["error", "consistent"],
"arrow-spacing": "error",
"lines-between-class-members": "error",
"no-mixed-operators": ["error", {
"groups": [["&", "|", "^", "~", "<<", ">>", ">>>", "&&", "||"]],
"allowSamePrecedence": false,
}],
"no-useless-constructor": "error",
"operator-assignment": "error",
// }}}
},
"overrides": [
Expand Down
2 changes: 0 additions & 2 deletions lib/media/closed_caption_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,6 @@ shaka.media.MuxJSClosedCaptionParser = class {
* @final
*/
shaka.media.NoopCaptionParser = class {
constructor() {}

/**
* @override
*/
Expand Down
2 changes: 0 additions & 2 deletions lib/offline/session_deleter.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ goog.require('shaka.util.ArrayUtils');
* Contains a utility method to delete persistent EME sessions.
*/
shaka.offline.SessionDeleter = class {
constructor() {}

/**
* Deletes the given sessions. This never fails and instead logs the error.
*
Expand Down
2 changes: 2 additions & 0 deletions lib/routing/walker.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,8 @@ shaka.routing.Walker = class {
// possible for "supported errors" to occur - errors that the code using
// the walker can't predict but can recover from.
try {
// TODO: This is probably a false-positive. See eslint/eslint#11687.
// eslint-disable-next-line require-atomic-updates
this.currentStep_ = this.implementation_.enterNode(
/* node= */ this.currentlyAt_,
/* has= */ this.currentlyWith_,
Expand Down
2 changes: 1 addition & 1 deletion test/media/play_rate_controller_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe('PlayRateController', () => {

// Make sure that when the playback rate set, if the new rate matches the
// current rate, the controller will not set the rate on the media element.
it('does not redundently set the playrate', ()=> {
it('does not redundently set the playrate', () => {
// Make sure we don't see the play rate change before and after we set the
// rate on the controller.
expect(setPlayRateSpy).not.toHaveBeenCalled();
Expand Down
2 changes: 1 addition & 1 deletion test/media/playhead_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ describe('Playhead', function() {

function setMockDate(seconds) {
const minutes = Math.floor(seconds / 60);
seconds = seconds % 60;
seconds %= 60;
const mockDate = new Date(2013, 9, 23, 7, minutes, seconds);
jasmine.clock().mockDate(mockDate);
}
Expand Down
2 changes: 1 addition & 1 deletion test/test/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ shaka.test.Util.waitForEndOrTimeout = (eventManager, target, timeout) => {
*/
shaka.test.Util.customMatchers_ = {
// Custom matcher for Element objects.
toEqualElement: (util, customEqualityTesters) =>{
toEqualElement: (util, customEqualityTesters) => {
return {
compare: shaka.test.Util.expectToEqualElementCompare_,
};
Expand Down

0 comments on commit b87a066

Please sign in to comment.