Skip to content

Commit

Permalink
enable lint correctness rules
Browse files Browse the repository at this point in the history
  • Loading branch information
pirxpilot committed Jan 14, 2024
1 parent 3a95137 commit 84b120a
Show file tree
Hide file tree
Showing 16 changed files with 50 additions and 28 deletions.
2 changes: 1 addition & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ app.set('view engine', 'jade');
app.use(logger('dev'));
app.use(cookieParser());
app.use(cachify);
app.use((req, res, next) => {
app.use((_req, res, next) => {
cachify.helpers().then(fns => {
res.locals.cachify = fns.cachify;
next();
Expand Down
24 changes: 23 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
"enabled": true,
"rules": {
"recommended": true,
"correctness": {
"all": true
},
"complexity": {
"noForEach": "off",
"useLiteralKeys": "off"
Expand All @@ -44,5 +47,24 @@
"noAssignInExpressions": "off"
}
}
}
},
"overrides": [
{
"include": [
"**/sw.template.js"
],
"linter": {
"rules": {
"correctness": {
"noUndeclaredVariables": "off"
}
}
},
"javascript": {
"globals": [
"options"
]
}
}
]
}
2 changes: 1 addition & 1 deletion lib/cli/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function fetchExample(resortId) {
resort = require(`../resorts/${resortId}/resort.json`);
curl(resort.dataUrl || resort.api || resort.url, resortId);
done = true;
} catch (e) {
} catch {
console.error(resortId, 'is not a valid resort ID');
process.exit(1);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/cli/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ function write(dst, json) {

function copy(src, dst, params) {
console.log('Generating %s...', dst);
fs.readFile(src, 'utf8', (err, data) => {
fs.readFile(src, 'utf8', (_err, data) => {
data = template(data)(params);
fs.writeFileSync(dst, data);
});
Expand Down
2 changes: 1 addition & 1 deletion lib/cli/noaa.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function writeDescriptor(resortId, descriptor) {
function readDescriptor(resortId) {
try {
return require(`../resorts/${resortId}/resort.json`);
} catch (e) {
} catch {
console.error(resortId, 'is not a valid resort ID');
process.exit(1);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/lifts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function fetch(resort, fn) {
}
debug("Fetch lift status for %s", resort.id);
const rfau = resort._rfau;
rfau.fn(rfau.url, resort._parseFn, (err, data) => {
rfau.fn(rfau.url, resort._parseFn, (_err, data) => {
Promise.resolve(data).then((data, err) => {
if (err || !data) {
data = {};
Expand Down
2 changes: 1 addition & 1 deletion lib/loaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function appendResorts(data, resorts) {

function load(fn) {
debug('Loading resorts...');
async.parallel(loaders, (err, results) => {
async.parallel(loaders, (_err, results) => {
const data = results.reduce(appendResorts, Object.create(null));
debug('Loaded %d resorts.', Object.keys(data).length);
fn(null, data);
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ function data() {

function init(fn) {
// all loaders
loaders.load((err, data) => {
loaders.load((_err, data) => {
initCache(data);
my.tags = tags(data);
my.all = Object.keys(cache);
Expand Down
8 changes: 4 additions & 4 deletions lib/routes/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const reportTo = JSON.stringify({
]
});

function csp(req, res, next) {
function csp(_req, res, next) {
const cspNonce = crypto.randomBytes(16).toString('base64');
res.locals.cspNonce = cspNonce;
res.header(CSP_HEADER_NAME, cspPolicy.replace('$random', cspNonce));
Expand All @@ -44,18 +44,18 @@ function csp(req, res, next) {
next();
}

function referrer(req, res, next) {
function referrer(_req, res, next) {
res.header('Referrer-Policy', 'no-referrer-when-downgrade');
next();
}

function feature(req, res, next) {
function feature(_req, res, next) {
res.header('Feature-Policy', `fullscreen 'self'`);
next();
}


function link(req, res, next) {
function link(_req, res, next) {
const preloadLinks = [{
path: '/stylesheets/fonts/lift-status.woff2',
as: 'font',
Expand Down
6 changes: 3 additions & 3 deletions lib/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function renderResorts(req, res, next) {
* /resort/<name> - display a specific resort
* /?resorts=<name1>,<name2>... - display resorts on the list
*/
function index(req, res, next) {
function index(req, _res, next) {
req.requested = req.params.resort || req.query.resorts;
req.opts = {
openSingle: true
Expand Down Expand Up @@ -92,7 +92,7 @@ function tag(req, res, next) {
next();
}

function about(req, res) {
function about(_req, res) {
res.render('about', {
title: title('About')
});
Expand Down Expand Up @@ -162,7 +162,7 @@ function meta(req, res, next) {

function routes(app) {

function reqData(req, res, next) {
function reqData(req, _res, next) {
req.data = app.data;
next();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const {

const DEBUG = NODE_ENV !== 'production';

function renderServiceWorker(req, res) {
function renderServiceWorker(_req, res) {
createServiceWorkerScript(res.locals).then(serviceWorkerScript => {
// do not cache service worker
res.header('Cache-Control', 'no-cache, max-age=0, must-revalidate');
Expand Down
4 changes: 2 additions & 2 deletions test/lifts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function testResort(name, ext, expected, opts = {}) {
const parse = makeParse(name);


function testHTML(t, done) {
function testHTML(_t, done) {
const stream = createReadStream(filename);

stream.on('error', done);
Expand All @@ -24,7 +24,7 @@ function testResort(name, ext, expected, opts = {}) {
}));
}

function testJSON(t, done) {
function testJSON(_t, done) {
const asyncParse = parse.isAsync ?
parse :
(data, fn) => process.nextTick(fn, null, parse(data));
Expand Down
10 changes: 5 additions & 5 deletions test/opening.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ const today = iso(now);
const future = iso(now + 2 * day);
const past = iso(now - 2 * day);

test('opening should be empty for missing dates', (t, done) => {
test('opening should be empty for missing dates', (_t, done) => {
opening({}, (err, od) => {
assert.ok(!od);
done(err);
});
});

test('opening should be empty for invalid dates', (t, done) => {
test('opening should be empty for invalid dates', (_t, done) => {
opening({
opening: 'abc'
}, (err, od) => {
Expand All @@ -30,7 +30,7 @@ test('opening should be empty for invalid dates', (t, done) => {
});
});

test('opening should be empty for past dates', (t, done) => {
test('opening should be empty for past dates', (_t, done) => {
opening({
opening: past
}, (err, od) => {
Expand All @@ -39,7 +39,7 @@ test('opening should be empty for past dates', (t, done) => {
});
});

test('opening should be empty for today', (t, done) => {
test('opening should be empty for today', (_t, done) => {
opening({
opening: today
}, (err, od) => {
Expand All @@ -48,7 +48,7 @@ test('opening should be empty for today', (t, done) => {
});
});

test('opening should be present for future dates', (t, done) => {
test('opening should be present for future dates', (_t, done) => {
opening({
opening: future
}, (err, od) => {
Expand Down
4 changes: 2 additions & 2 deletions test/weather/noaa.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const noaa = require('../../lib/weather/noaa');

require('../replay');

test('noaa should return empty forecast if location is missing', (t, done) => {
test('noaa should return empty forecast if location is missing', (_t, done) => {
noaa({
ll: [0, 0]
}, (err, forecast) => {
Expand All @@ -14,7 +14,7 @@ test('noaa should return empty forecast if location is missing', (t, done) => {
});
});

test('noaa should return forecast for valid location', (t, done) => {
test('noaa should return forecast for valid location', (_t, done) => {
noaa({
// Killington, VT
noaa: 'BTV/107,21',
Expand Down
2 changes: 1 addition & 1 deletion test/weather/openweather.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const openweather = require('../../lib/weather/openweather');

require('../replay');

test('openweather should return forecast', (t, done) => {
test('openweather should return forecast', (_t, done) => {
openweather({
// Killington, VT
ll: [-72.7933, 43.6647]
Expand Down
4 changes: 2 additions & 2 deletions test/webcams.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ if (process.env.REPLAY !== 'record') {
process.env.WEBCAMS_API_KEY = 'TEST_KEY';
}

test('webcams should return no webcams if location is missing', (t, done) => {
test('webcams should return no webcams if location is missing', (_t, done) => {
webcams({}, (err, webcams) => {
assert.ifError(err);
assert.ok(!webcams);
done();
});
});

test('webcams should return webcams for valid location', (t, done) => {
test('webcams should return webcams for valid location', (_t, done) => {
webcams({
counter: 1,
ll: [7.98, 46.54] // from API examples https://windy.com/webcams/1697038975'
Expand Down

0 comments on commit 84b120a

Please sign in to comment.