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 @@
"array-callback-return": "error",
"block-scoped-var": "error",
"comma-dangle": ["error", "always-multiline"],
"consistent-this": ["error", "self"],
"consistent-return": "error",
"curly": "error",
"dot-notation": "error",
......
/* jshint node: true */
/* eslint consistent-this: ["error", "vm"] */
'use strict';
var annotationMetadata = require('../annotation-metadata');
......
......@@ -4,19 +4,19 @@ var VIA_PREFIX = 'https://via.hypothes.is/';
// @ngInject
function ShareDialogController($scope, $element, crossframe) {
var ctrl = this;
var self = this;
function updateViaLink(frames) {
if (!frames.length) {
ctrl.viaPageLink = '';
self.viaPageLink = '';
return;
}
// 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) {
ctrl.viaPageLink = frames[0].uri;
self.viaPageLink = frames[0].uri;
} else {
ctrl.viaPageLink = VIA_PREFIX + frames[0].uri;
self.viaPageLink = VIA_PREFIX + frames[0].uri;
}
}
......
......@@ -2,10 +2,7 @@
// @ngInject
function SidebarTutorialController(session) {
/*jshint validthis:true */
var vm = this;
vm.showSidebarTutorial = function () {
this.showSidebarTutorial = function () {
if (session.state.preferences) {
if (session.state.preferences.show_sidebar_tutorial) {
return true;
......@@ -14,7 +11,7 @@ function SidebarTutorialController(session) {
return false;
};
vm.dismiss = function () {
this.dismiss = function () {
session.dismiss_sidebar_tutorial();
};
}
......
......@@ -30,7 +30,7 @@ describe('excerpt directive', function () {
beforeEach(function () {
function FakeOverflowMonitor(ctrl) {
fakeOverflowMonitor = this;
fakeOverflowMonitor = this; // eslint-disable-line consistent-this
this.ctrl = ctrl;
this.check = sinon.stub();
......
......@@ -4,25 +4,25 @@ var dateUtil = require('../date-util');
// @ngInject
function TimestampController($scope, time) {
var vm = this;
// 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')
vm.absoluteTimestamp = '';
this.absoluteTimestamp = '';
var cancelTimestampRefresh;
var self = this;
function updateTimestamp() {
vm.relativeTimestamp = time.toFuzzyString(vm.timestamp);
vm.absoluteTimestamp = dateUtil.format(new Date(vm.timestamp));
self.relativeTimestamp = time.toFuzzyString(self.timestamp);
self.absoluteTimestamp = dateUtil.format(new Date(self.timestamp));
if (vm.timestamp) {
if (self.timestamp) {
if (cancelTimestampRefresh) {
cancelTimestampRefresh();
}
cancelTimestampRefresh = time.decayingInterval(vm.timestamp, function () {
cancelTimestampRefresh = time.decayingInterval(self.timestamp, function () {
updateTimestamp();
$scope.$digest();
});
......
......@@ -9,7 +9,7 @@ var proxyquire = require('proxyquire');
var fakeWebSocket = null;
function FakeSocket() {
fakeWebSocket = this;
fakeWebSocket = this; // eslint-disable-line consistent-this
this.messages = [];
this.didClose = false;
......
......@@ -9,7 +9,7 @@ describe('websocket wrapper', function () {
function FakeWebSocket() {
this.close = sinon.stub();
this.send = sinon.stub();
fakeSocket = this;
fakeSocket = this; // eslint-disable-line consistent-this
}
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