Skip to content

Commit

Permalink
Fix eslint config (#34)
Browse files Browse the repository at this point in the history
Upgrade devDependencies, add linting scripts, update eslintrc, run test coverage in test.yml
  • Loading branch information
elliotwutingfeng authored Dec 13, 2022
1 parent eb3f902 commit 36380a7
Show file tree
Hide file tree
Showing 16 changed files with 5,565 additions and 12,084 deletions.
6 changes: 5 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"extends": "airbnb"
"extends": ["plugin:import/recommended", "plugin:jsx-a11y/recommended", "prettier"],
"plugins": ["import", "jsx-a11y", "prettier"],
"rules": {
"prettier/prettier": ["error"]
}
}
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ jobs:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
node-version: [16.x, 18.x]

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
*.log
coverage
.nyc_output
5 changes: 0 additions & 5 deletions .travis.yml

This file was deleted.

31 changes: 15 additions & 16 deletions Gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* eslint import/no-extraneous-dependencies: ["error", {"devDependencies": true}] */

const babel = require('gulp-babel');
const browserify = require('browserify');
const gulp = require('gulp');
const rename = require('gulp-rename');
const source = require('vinyl-source-stream');
const uglify = require('gulp-uglify');
const babel = require("gulp-babel");
const browserify = require("browserify");
const gulp = require("gulp");
const rename = require("gulp-rename");
const source = require("vinyl-source-stream");
const uglify = require("gulp-uglify");

/**
* Prepares the files for browser usage
Expand All @@ -14,19 +14,18 @@ const uglify = require('gulp-uglify');
* - Transpile with Babel
* - Minify with uglify
*/
gulp.task('build', ['bundle'], () => {
gulp.src('./dist/dijkstra.js')
gulp.task("build", ["bundle"], () => {
gulp
.src("./dist/dijkstra.js")
.pipe(babel())
.pipe(gulp.dest('./dist'))
.pipe(gulp.dest("./dist"))
.pipe(uglify())
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('./dist'));
.pipe(rename({ suffix: ".min" }))
.pipe(gulp.dest("./dist"));
});

gulp.task('bundle', () => {
const b = browserify({ entries: './libs/Graph.js' });
gulp.task("bundle", () => {
const b = browserify({ entries: "./libs/Graph.js" });

return b.bundle()
.pipe(source('dijkstra.js'))
.pipe(gulp.dest('./dist'));
return b.bundle().pipe(source("dijkstra.js")).pipe(gulp.dest("./dist"));
});
10 changes: 4 additions & 6 deletions libs/Graph.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
const Queue = require('./PriorityQueue');
const removeDeepFromMap = require('./removeDeepFromMap');
const toDeepMap = require('./toDeepMap');
const validateDeep = require('./validateDeep');
const Queue = require("./PriorityQueue");
const removeDeepFromMap = require("./removeDeepFromMap");
const toDeepMap = require("./toDeepMap");
const validateDeep = require("./validateDeep");

/** Creates and manages a graph */
class Graph {

/**
* Creates a new Graph, optionally initializing it a nodes graph representation.
*
Expand Down Expand Up @@ -287,7 +286,6 @@ class Graph {
shortestPath(...args) {
return this.path(...args);
}

}

module.exports = Graph;
4 changes: 1 addition & 3 deletions libs/PriorityQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* provided by the class.
*/
class PriorityQueue {

/**
* Creates a new empty priority queue
*/
Expand Down Expand Up @@ -99,9 +98,8 @@ class PriorityQueue {
* @return {object}
*/
get(key) {
return this.queue.find(element => element.key === key);
return this.queue.find((element) => element.key === key);
}

}

module.exports = PriorityQueue;
7 changes: 5 additions & 2 deletions libs/toDeepMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ function toDeepMap(source) {
keys.forEach((key) => {
const val = source[key];

if (val !== null && typeof val === 'object' && !Array.isArray(val)) {
if (val !== null && typeof val === "object" && !Array.isArray(val)) {
return map.set(key, toDeepMap(val));
}

if (!isValidNode(val)) {
throw new Error(`Could not add node at key "${key}", make sure it's a valid node`, val);
throw new Error(
`Could not add node at key "${key}", make sure it's a valid node`,
val
);
}

return map.set(key, Number(val));
Expand Down
8 changes: 5 additions & 3 deletions libs/validateDeep.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ function validateDeep(map) {
}

map.forEach((value, key) => {
if (typeof value === 'object' && value instanceof Map) {
if (typeof value === "object" && value instanceof Map) {
validateDeep(value);
return;
}

if (typeof value !== 'number' || value <= 0) {
throw new Error(`Values must be numbers greater than 0. Found value ${value} at ${key}`);
if (typeof value !== "number" || value <= 0) {
throw new Error(
`Values must be numbers greater than 0. Found value ${value} at ${key}`
);
}
});
}
Expand Down
Loading

0 comments on commit 36380a7

Please sign in to comment.