Skip to content

Commit

Permalink
Merge pull request #46 from CMU-17313Q/jshintintegration
Browse files Browse the repository at this point in the history
Integrating JShint into our Workflow
  • Loading branch information
khalifat3 authored Oct 30, 2024
2 parents 064ef56 + dc3d914 commit 4c2ff42
Show file tree
Hide file tree
Showing 27 changed files with 116 additions and 35 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/jshint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: JSHint

on:
push:
branches:
- main
pull_request:
branches:
- main

defaults:
run:
shell: bash

permissions:
contents: read

jobs:
jshint:
permissions:
checks: write
contents: read
name: JSHint
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
node: [16]
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3

- run: cp install/package.json package.json

- name: Install Node
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}

- name: NPM Install
uses: bahmutov/npm-install@v1
with:
useLockFile: false

- name: Run JSHint
run: npm run jshint
11 changes: 11 additions & 0 deletions .jshintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
node_modules/
/build
public/
test/user.js
src/topics/unread.js
src/privileges/helpers.js
src/meta/css.js
src/database/mongo/sorted/intersect.js
src/controllers/helpers.js
src/constants.js
src/cli/user.js
22 changes: 22 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"esversion": 11,
"node": true,
"mocha": true,
"browser": true,
"globals": {
"jQuery": false,
"$": true,
"ajaxify": false,
"config": false,
"socket": true,
"app": true,
"overrides": true,
"utils": true,
"define": true,
"bootbox": true,
"escape": true,
"alert": true,
"self": true,
"AbortSignal": true
}
}
2 changes: 1 addition & 1 deletion install/docker/mongodb-user-init.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion install/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"lint": "eslint --cache ./nodebb .",
"test": "nyc --reporter=html --reporter=text-summary mocha",
"coverage": "nyc report --reporter=text-lcov > ./coverage/lcov.info",
"coveralls": "nyc report --reporter=text-lcov | coveralls && rm -r coverage"
"coveralls": "nyc report --reporter=text-lcov | coveralls && rm -r coverage",
"jshint": "jshint ."
},
"nyc": {
"exclude": [
Expand Down
2 changes: 1 addition & 1 deletion src/api/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ usersAPI.generateExport = async (caller, { uid, type }) => {
if (!validTypes.includes(type)) {
throw new Error('[[error:invalid-data]]');
}
if (!utils.isNumber(uid) || !(parseInt(uid, 10) > 0)) {
if (!utils.isNumber(uid) || (parseInt(uid, 10) <= 0)) {
throw new Error('[[error:invalid-uid]]');
}
const count = await db.incrObjectField('locks', `export:${uid}${type}`);
Expand Down
4 changes: 2 additions & 2 deletions src/categories/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ module.exports = function (Categories) {
};

Categories.isIgnored = async function (cids, uid) {
if (!(parseInt(uid, 10) > 0)) {
if (parseInt(uid, 10) <= 0) {
return cids.map(() => false);
}
const states = await Categories.getWatchState(cids, uid);
return states.map(state => state === Categories.watchStates.ignoring);
};

Categories.getWatchState = async function (cids, uid) {
if (!(parseInt(uid, 10) > 0)) {
if (parseInt(uid, 10) <= 0) {
return cids.map(() => Categories.watchStates.notwatching);
}
if (!Array.isArray(cids) || !cids.length) {
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/accounts/chats.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ chatsController.redirectToMessage = async function (req, res, next) {
return next();
}
const index = await db.sortedSetRank(`chat:room:${roomId}:mids`, mid);
if (!(parseInt(index, 10) >= 0)) {
if (parseInt(index, 10) < 0) {
return next();
}

Expand Down
2 changes: 1 addition & 1 deletion src/database/redis/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ connection.connect = async function (options) {
}

const dbIdx = parseInt(options.database, 10);
if (!(dbIdx >= 0)) {
if (dbIdx < 0) {
throw new Error('[[error:no-database-selected]]');
}

Expand Down
2 changes: 1 addition & 1 deletion src/flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ Flags.appendNote = async function (flagId, uid, note, datetime) {
await Flags.deleteNote(flagId, datetime);
} catch (e) {
// Do not throw if note doesn't exist
if (!e.message === '[[error:invalid-data]]') {
if (e.message !== '[[error:invalid-data]]') {
throw e;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/groups/ownership.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = function (Groups) {
Groups.ownership = {};

Groups.ownership.isOwner = async function (uid, groupName) {
if (!(parseInt(uid, 10) > 0)) {
if (parseInt(uid, 10) <= 0) {
return false;
}
return await db.isSetMember(`group:${groupName}:owners`, uid);
Expand Down
2 changes: 1 addition & 1 deletion src/messaging/rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ module.exports = function (Messaging) {
};

Messaging.toggleOwner = async (uid, roomId, state = null) => {
if (!(parseInt(uid, 10) > 0) || !roomId) {
if (parseInt(uid, 10) <= 0 || !roomId) {
throw new Error('[[error:invalid-data]]');
}

Expand Down
2 changes: 1 addition & 1 deletion src/messaging/unread.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const io = require('../socket.io');

module.exports = function (Messaging) {
Messaging.getUnreadCount = async (uid) => {
if (!(parseInt(uid, 10) > 0)) {
if (parseInt(uid, 10) <= 0) {
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion src/meta/configs.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ async function processConfig(data) {
function ensureInteger(data, field, min) {
if (data.hasOwnProperty(field)) {
data[field] = parseInt(data[field], 10);
if (!(data[field] >= min)) {
if (data[field] < min) {
throw new Error('[[error:invalid-data]]');
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ Notifications.markRead = async function (nid, uid) {
};

Notifications.markUnread = async function (nid, uid) {
if (!(parseInt(uid, 10) > 0) || !nid) {
if ((parseInt(uid, 10) <= 0) || !nid) {
return;
}
const notification = await db.getObject(`notifications:${nid}`);
Expand All @@ -346,7 +346,7 @@ Notifications.markUnread = async function (nid, uid) {

Notifications.markReadMultiple = async function (nids, uid) {
nids = nids.filter(Boolean);
if (!Array.isArray(nids) || !nids.length || !(parseInt(uid, 10) > 0)) {
if (!Array.isArray(nids) || !nids.length || (parseInt(uid, 10) <= 0)) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/socket.io/categories.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ SocketCategories.isModerator = async function (socket, cid) {
SocketCategories.loadMoreSubCategories = async function (socket, data) {
sockets.warnDeprecated(socket, `GET /api/v3/categories/:cid/children`);

if (!data || !data.cid || !(parseInt(data.start, 10) >= 0)) {
if (!data || !data.cid || parseInt(data.start, 10) < 0) {
throw new Error('[[error:invalid-data]]');
}

Expand Down
2 changes: 1 addition & 1 deletion src/socket.io/modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ SocketModules.chats.leavePublic = async function (socket, roomIds) {
};

async function joinLeave(socket, roomIds, method, prefix = 'chat_room') {
if (!(socket.uid > 0)) {
if (socket.uid <= 0) {
throw new Error('[[error:not-allowed]]');
}
if (!Array.isArray(roomIds)) {
Expand Down
2 changes: 1 addition & 1 deletion src/topics/follow.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module.exports = function (Topics) {
};

async function setWatching(method1, method2, hook, tid, uid) {
if (!(parseInt(uid, 10) > 0)) {
if (parseInt(uid, 10) <= 0) {
throw new Error('[[error:not-logged-in]]');
}
const exists = await Topics.exists(tid);
Expand Down
4 changes: 2 additions & 2 deletions src/topics/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ module.exports = function (Topics) {
};

Topics.followTag = async (tag, uid) => {
if (!(parseInt(uid, 10) > 0)) {
if (parseInt(uid, 10) <= 0) {
throw new Error('[[error:not-logged-in]]');
}
const now = Date.now();
Expand All @@ -582,7 +582,7 @@ module.exports = function (Topics) {
};

Topics.unfollowTag = async (tag, uid) => {
if (!(parseInt(uid, 10) > 0)) {
if (parseInt(uid, 10) <= 0) {
throw new Error('[[error:not-logged-in]]');
}
await db.sortedSetRemoveBulk([
Expand Down
4 changes: 2 additions & 2 deletions src/topics/unread.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ module.exports = function (Topics) {
}

async function getWatchedTrackedCids(uid) {
if (!(parseInt(uid, 10) > 0)) {
if (parseInt(uid, 10) <= 0) {
return [];
}
const cids = await user.getCategoriesByStates(uid, [
Expand Down Expand Up @@ -349,7 +349,7 @@ module.exports = function (Topics) {
};

Topics.hasReadTopics = async function (tids, uid) {
if (!(parseInt(uid, 10) > 0)) {
if (parseInt(uid, 10) <= 0) {
return tids.map(() => false);
}
const [topicScores, userScores, tids_unread, blockedUids] = await Promise.all([
Expand Down
2 changes: 1 addition & 1 deletion src/user/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const batch = require('../batch');

module.exports = function (User) {
User.logIP = async function (uid, ip) {
if (!(parseInt(uid, 10) > 0)) {
if (parseInt(uid, 10) <= 0) {
return;
}
const now = Date.now();
Expand Down
6 changes: 3 additions & 3 deletions src/user/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = function (User) {
User.auth = {};

User.auth.logAttempt = async function (uid, ip) {
if (!(parseInt(uid, 10) > 0)) {
if (parseInt(uid, 10) <= 0) {
return;
}
const exists = await db.exists(`lockout:${uid}`);
Expand All @@ -38,7 +38,7 @@ module.exports = function (User) {
};

User.auth.getFeedToken = async function (uid) {
if (!(parseInt(uid, 10) > 0)) {
if (parseInt(uid, 10) <= 0) {
return;
}
const _token = await db.getObjectField(`user:${uid}`, 'rss_token');
Expand Down Expand Up @@ -100,7 +100,7 @@ module.exports = function (User) {
}

User.auth.addSession = async function (uid, sessionId) {
if (!(parseInt(uid, 10) > 0)) {
if (parseInt(uid, 10) <= 0) {
return;
}

Expand Down
10 changes: 5 additions & 5 deletions src/user/categories.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const plugins = require('../plugins');

module.exports = function (User) {
User.setCategoryWatchState = async function (uid, cids, state) {
if (!(parseInt(uid, 10) > 0)) {
if (parseInt(uid, 10) <= 0) {
return;
}
const isStateValid = Object.values(categories.watchStates).includes(parseInt(state, 10));
Expand All @@ -24,7 +24,7 @@ module.exports = function (User) {
};

User.getCategoryWatchState = async function (uid) {
if (!(parseInt(uid, 10) > 0)) {
if (parseInt(uid, 10) <= 0) {
return {};
}

Expand All @@ -34,7 +34,7 @@ module.exports = function (User) {
};

User.getIgnoredCategories = async function (uid) {
if (!(parseInt(uid, 10) > 0)) {
if (parseInt(uid, 10) <= 0) {
return [];
}
const cids = await User.getCategoriesByStates(uid, [categories.watchStates.ignoring]);
Expand All @@ -46,7 +46,7 @@ module.exports = function (User) {
};

User.getWatchedCategories = async function (uid) {
if (!(parseInt(uid, 10) > 0)) {
if (parseInt(uid, 10) <= 0) {
return [];
}
let cids = await User.getCategoriesByStates(uid, [categories.watchStates.watching]);
Expand All @@ -61,7 +61,7 @@ module.exports = function (User) {

User.getCategoriesByStates = async function (uid, states) {
const cids = await categories.getAllCidsFromSet('categories:cid');
if (!(parseInt(uid, 10) > 0)) {
if (parseInt(uid, 10) <= 0) {
return cids;
}
const userState = await categories.getWatchState(cids, uid);
Expand Down
2 changes: 1 addition & 1 deletion src/user/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ UserEmail.confirmByCode = async function (code, sessionId) {

// confirm uid's email via ACP
UserEmail.confirmByUid = async function (uid, callerUid = 0) {
if (!(parseInt(uid, 10) > 0)) {
if (parseInt(uid, 10) <= 0) {
throw new Error('[[error:invalid-uid]]');
}
callerUid = callerUid || uid;
Expand Down
2 changes: 1 addition & 1 deletion src/user/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ User.getPrivileges = async function (uid) {
};

User.isPrivileged = async function (uid) {
if (!(parseInt(uid, 10) > 0)) {
if (parseInt(uid, 10) <= 0) {
return false;
}
const results = await User.getPrivileges(uid);
Expand Down
4 changes: 2 additions & 2 deletions src/user/online.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const meta = require('../meta');

module.exports = function (User) {
User.updateLastOnlineTime = async function (uid) {
if (!(parseInt(uid, 10) > 0)) {
if (parseInt(uid, 10) <= 0) {
return;
}
const userData = await db.getObjectFields(`user:${uid}`, ['userslug', 'status', 'lastonline']);
Expand All @@ -19,7 +19,7 @@ module.exports = function (User) {
};

User.updateOnlineUsers = async function (uid) {
if (!(parseInt(uid, 10) > 0)) {
if (parseInt(uid, 10) <= 0) {
return;
}
const [exists, userOnlineTime] = await Promise.all([
Expand Down
2 changes: 1 addition & 1 deletion src/user/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ module.exports = function (User) {

async function incrementUserFieldAndSetBy(uid, field, set, value) {
value = parseInt(value, 10);
if (!value || !field || !(parseInt(uid, 10) > 0)) {
if (!value || !field || (parseInt(uid, 10) <= 0)) {
return;
}
const exists = await User.exists(uid);
Expand Down

0 comments on commit 4c2ff42

Please sign in to comment.