Skip to content

Commit

Permalink
Check for unused variables
Browse files Browse the repository at this point in the history
Add the 'unused' option to our JSHint configuration and fix all the
warnings that it raises. Several times an import was not necessary any
longer but it was still left at the top of the file.

In some other cases we have to use void or array elisions to avoid the
warning. This is not so elegant so I've opened up an issue with JSHint to
see if an easier way can be found:
jshint/jshint#2729
  • Loading branch information
ptomato committed Oct 23, 2015
1 parent 32da9cf commit 8988015
Show file tree
Hide file tree
Showing 17 changed files with 26 additions and 18 deletions.
1 change: 1 addition & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"sub": true,
"trailing": true,
"undef": true,
"unused": true,
"predef": [
"addCustomEqualityTester",
"afterAll",
Expand Down
1 change: 0 additions & 1 deletion bin/jasmine.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
/* global jasmineImporter */

const GLib = imports.gi.GLib;
const System = imports.system;

// Create a separate GJS importer object for Jasmine modules, so that Jasmine's
// modules are not exposed to test code (e.g. client code might have its own
Expand Down
7 changes: 4 additions & 3 deletions src/command.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* global jasmineImporter */
/* exported run */

const Format = imports.format;
const Gio = imports.gi.Gio;
Expand Down Expand Up @@ -32,7 +33,7 @@ function loadConfig(configFilePath) {
let config = {};

try {
let [success, contents, length, etag] = configFile.load_contents(null);
let [, contents] = configFile.load_contents(null);
config = JSON.parse(contents);
} catch (e) {
throw new Error('Configuration not read from ' + configFile.get_path());
Expand Down Expand Up @@ -124,7 +125,7 @@ function run(_jasmine, argv, config={}, timeout=-1) {
}

if (config.options) {
let [configFiles, configOptions] = Options.parseOptions(_ensureArray(config.options));
let [, configOptions] = Options.parseOptions(_ensureArray(config.options));
// Command-line options should always override config file options
Object.keys(configOptions).forEach((key) => {
if (!(key in options))
Expand Down Expand Up @@ -178,7 +179,7 @@ function run(_jasmine, argv, config={}, timeout=-1) {
junitStream.put_string(str, null);
},
});
junitReporter.connect('complete', (success) => junitStream.close(null));
junitReporter.connect('complete', () => junitStream.close(null));
_jasmine.addReporter(junitReporter);
}

Expand Down
4 changes: 2 additions & 2 deletions src/consoleReporter.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* global jasmineImporter */
/* exported DefaultReporter */

const Format = imports.format;
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const GObject = imports.gi.GObject;
const Lang = imports.lang;

Expand Down Expand Up @@ -118,7 +118,7 @@ const ConsoleReporter = new Lang.Class({

// Called with an "info" object with the following property:
// totalSpecsDefined - number of specs to be run
jasmineStarted: function (info) {
jasmineStarted: function () {
this.emit('started');
this.startTimer('main');
},
Expand Down
3 changes: 2 additions & 1 deletion src/jasmineBoot.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* global jasmineImporter */
/* exported Jasmine */

const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
Expand Down Expand Up @@ -116,7 +117,7 @@ const Jasmine = new Lang.Class({
let modulePath = GLib.path_get_dirname(file);
let moduleName = GLib.path_get_basename(file).slice(0, -3); // .js
imports.searchPath.unshift(modulePath);
let dummy = imports[moduleName];
void imports[moduleName];
imports.searchPath = oldSearchPath;
});
},
Expand Down
1 change: 1 addition & 0 deletions src/junitReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Unfortunately, the JUnit format is woefully underspecified.

/* global jasmineImporter */
/* exported JUnitReporter */

const GLib = imports.gi.GLib;
const Lang = imports.lang;
Expand Down
3 changes: 2 additions & 1 deletion src/options.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* exported parseOptions */

const Format = imports.format;
const Lang = imports.lang;
const System = imports.system;

String.prototype.format = Format.format;
Expand Down
1 change: 1 addition & 0 deletions src/tapReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// See http://testanything.org/tap-specification.html

/* global jasmineImporter */
/* exported TapReporter */

const Format = imports.format;
const Lang = imports.lang;
Expand Down
2 changes: 2 additions & 0 deletions src/timer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* exported installAPI, createDefaultTimer */

const GLib = imports.gi.GLib;
const Mainloop = imports.mainloop;

Expand Down
2 changes: 2 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* exported indent */

function indent(str, spaces) {
return str.split('\n').map((line) => {
if (line === '')
Expand Down
1 change: 1 addition & 0 deletions src/verboseReporter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* global jasmineImporter */
/* exported VerboseReporter */

const Lang = imports.lang;

Expand Down
2 changes: 0 additions & 2 deletions test/focusedSpecIntegrationTest.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const GLib = imports.gi.GLib;

// This is a test of focused suites and specs with the fdescribe() and fit()
// functions. It's taken from Jasmine's documentation suite:
// http://jasmine.github.io/2.2/focused_specs.html
Expand Down
2 changes: 1 addition & 1 deletion test/jasmineBootSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let envSrcdir = GLib.getenv('SRCDIR');
const SRCDIR = envSrcdir? envSrcdir + '/' : '';

let customMatchers = {
toMatchAllFiles: function (util, customEqualityTesters) {
toMatchAllFiles: function () {
return {
compare: function (actual, expected) {
let result = {
Expand Down
2 changes: 2 additions & 0 deletions test/jasmineIntegrationTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
// run by default, but you don't want your tests to take 9 seconds when you run
// them from the command line using "jasmine test".

/* global setInterval, setTimeout */

const GLib = imports.gi.GLib;

describe('Jasmine integration test', function () {
Expand Down
5 changes: 1 addition & 4 deletions test/junitReporterSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ describe('The JUnit reporter', function () {
// present such as, <properties>, so we cannot rely on the element with ID 0
// being the first child of <testsuites>.
function findSuite(tree, id) {
let retval;
for (let index = 0; index < tree.children.length; index++) {
let child = tree.children[index];
if (child.name === 'testsuite' && child.attrs['id'] === id)
Expand Down Expand Up @@ -386,9 +385,7 @@ describe('The JUnit reporter', function () {

let tree = JSON.parse(out.getOutput());
let testsuite = findSuite(tree, 0);
expect(function () {
let date = Date.parse(testsuite.attrs['timestamp']);
}).not.toThrow();
expect(() => Date.parse(testsuite.attrs['timestamp'])).not.toThrow();
});

it('flattens nested suites', function () {
Expand Down
6 changes: 3 additions & 3 deletions test/optionsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ describe('Argument parser', function () {
});

it('stores values in the order they are given on the command line', function () {
let [files, namespace] = Options.parseOptions(['--no-color', '--color']);
let [, namespace] = Options.parseOptions(['--no-color', '--color']);
expect(namespace['color']).toBe(true);
});

it('stores the given value for an "append" argument', function () {
let [files, namespace] = Options.parseOptions(['--exclude', 'file.js']);
let [, namespace] = Options.parseOptions(['--exclude', 'file.js']);
expect(namespace['exclude']).toEqual(['file.js']);
});

it('stores multiple values for an "append" argument appearing multiple times', function () {
let [files, namespace] = Options.parseOptions([
let [, namespace] = Options.parseOptions([
'--exclude', 'file.js',
'--exclude', 'file2.js',
]);
Expand Down
1 change: 1 addition & 0 deletions test/utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* exported add */
function add(a, b) {
return a + b;
}

0 comments on commit 8988015

Please sign in to comment.