Commit 1ef5e770 authored by Robert Knight's avatar Robert Knight

Enforce consistent naming of aliases for `this`

Only allow use of `this` or `self` to refer to the 'this' context
object in a method.
parent df84961e
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
"array-callback-return": "error", "array-callback-return": "error",
"block-scoped-var": "error", "block-scoped-var": "error",
"comma-dangle": ["error", "always-multiline"], "comma-dangle": ["error", "always-multiline"],
"consistent-this": ["error", "self"],
"consistent-return": "error", "consistent-return": "error",
"curly": "error", "curly": "error",
"dot-notation": "error", "dot-notation": "error",
......
/* jshint node: true */ /* eslint consistent-this: ["error", "vm"] */
'use strict'; 'use strict';
var annotationMetadata = require('../annotation-metadata'); var annotationMetadata = require('../annotation-metadata');
......
...@@ -4,19 +4,19 @@ var VIA_PREFIX = 'https://via.hypothes.is/'; ...@@ -4,19 +4,19 @@ var VIA_PREFIX = 'https://via.hypothes.is/';
// @ngInject // @ngInject
function ShareDialogController($scope, $element, crossframe) { function ShareDialogController($scope, $element, crossframe) {
var ctrl = this; var self = this;
function updateViaLink(frames) { function updateViaLink(frames) {
if (!frames.length) { if (!frames.length) {
ctrl.viaPageLink = ''; self.viaPageLink = '';
return; return;
} }
// Check to see if we are on a via page. If so, we just return the URI. // Check to see if we are on a via page. If so, we just return the URI.
if (frames[0].uri.indexOf(VIA_PREFIX) === 0) { if (frames[0].uri.indexOf(VIA_PREFIX) === 0) {
ctrl.viaPageLink = frames[0].uri; self.viaPageLink = frames[0].uri;
} else { } else {
ctrl.viaPageLink = VIA_PREFIX + frames[0].uri; self.viaPageLink = VIA_PREFIX + frames[0].uri;
} }
} }
......
...@@ -2,10 +2,7 @@ ...@@ -2,10 +2,7 @@
// @ngInject // @ngInject
function SidebarTutorialController(session) { function SidebarTutorialController(session) {
/*jshint validthis:true */ this.showSidebarTutorial = function () {
var vm = this;
vm.showSidebarTutorial = function () {
if (session.state.preferences) { if (session.state.preferences) {
if (session.state.preferences.show_sidebar_tutorial) { if (session.state.preferences.show_sidebar_tutorial) {
return true; return true;
...@@ -14,7 +11,7 @@ function SidebarTutorialController(session) { ...@@ -14,7 +11,7 @@ function SidebarTutorialController(session) {
return false; return false;
}; };
vm.dismiss = function () { this.dismiss = function () {
session.dismiss_sidebar_tutorial(); session.dismiss_sidebar_tutorial();
}; };
} }
......
...@@ -30,7 +30,7 @@ describe('excerpt directive', function () { ...@@ -30,7 +30,7 @@ describe('excerpt directive', function () {
beforeEach(function () { beforeEach(function () {
function FakeOverflowMonitor(ctrl) { function FakeOverflowMonitor(ctrl) {
fakeOverflowMonitor = this; fakeOverflowMonitor = this; // eslint-disable-line consistent-this
this.ctrl = ctrl; this.ctrl = ctrl;
this.check = sinon.stub(); this.check = sinon.stub();
......
...@@ -4,25 +4,25 @@ var dateUtil = require('../date-util'); ...@@ -4,25 +4,25 @@ var dateUtil = require('../date-util');
// @ngInject // @ngInject
function TimestampController($scope, time) { function TimestampController($scope, time) {
var vm = this;
// A fuzzy, relative (eg. '6 days ago') format of the timestamp. // A fuzzy, relative (eg. '6 days ago') format of the timestamp.
vm.relativeTimestamp = null; this.relativeTimestamp = null;
// A formatted version of the timestamp (eg. 'Tue 22nd Dec 2015, 16:00') // A formatted version of the timestamp (eg. 'Tue 22nd Dec 2015, 16:00')
vm.absoluteTimestamp = ''; this.absoluteTimestamp = '';
var cancelTimestampRefresh; var cancelTimestampRefresh;
var self = this;
function updateTimestamp() { function updateTimestamp() {
vm.relativeTimestamp = time.toFuzzyString(vm.timestamp); self.relativeTimestamp = time.toFuzzyString(self.timestamp);
vm.absoluteTimestamp = dateUtil.format(new Date(vm.timestamp)); self.absoluteTimestamp = dateUtil.format(new Date(self.timestamp));
if (vm.timestamp) { if (self.timestamp) {
if (cancelTimestampRefresh) { if (cancelTimestampRefresh) {
cancelTimestampRefresh(); cancelTimestampRefresh();
} }
cancelTimestampRefresh = time.decayingInterval(vm.timestamp, function () { cancelTimestampRefresh = time.decayingInterval(self.timestamp, function () {
updateTimestamp(); updateTimestamp();
$scope.$digest(); $scope.$digest();
}); });
......
...@@ -9,7 +9,7 @@ var proxyquire = require('proxyquire'); ...@@ -9,7 +9,7 @@ var proxyquire = require('proxyquire');
var fakeWebSocket = null; var fakeWebSocket = null;
function FakeSocket() { function FakeSocket() {
fakeWebSocket = this; fakeWebSocket = this; // eslint-disable-line consistent-this
this.messages = []; this.messages = [];
this.didClose = false; this.didClose = false;
......
...@@ -9,7 +9,7 @@ describe('websocket wrapper', function () { ...@@ -9,7 +9,7 @@ describe('websocket wrapper', function () {
function FakeWebSocket() { function FakeWebSocket() {
this.close = sinon.stub(); this.close = sinon.stub();
this.send = sinon.stub(); this.send = sinon.stub();
fakeSocket = this; fakeSocket = this; // eslint-disable-line consistent-this
} }
FakeWebSocket.OPEN = 1; FakeWebSocket.OPEN = 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment