Skip to content

refactor: Add lint and prettier #2492

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
24 changes: 20 additions & 4 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,39 @@
{
"root": true,
"extends": "eslint:recommended",
"env": {
"es6": true,
"node": true,
"browser": true
},
"parser": "@babel/eslint-parser",
"extends": "eslint:recommended",
"plugins": [
"react"
],
"parserOptions": {
"sourceType": "module"
"ecmaVersion": 6,
"sourceType": "module",
"requireConfigFile": false
},
"plugins": ["react"],
"rules": {
"indent": ["error", 2, { "SwitchCase": 1 }],
"linebreak-style": ["error", "unix"],
"no-trailing-spaces": 2,
"eol-last": 2,
"space-in-parens": ["error", "never"],
"no-multiple-empty-lines": 1,
"prefer-const": "error",
"space-infix-ops": "error",
"no-useless-escape": "off",
"require-atomic-updates": "off",
"react/jsx-uses-vars": 1,
"react/jsx-uses-react": 1,
"react/react-in-jsx-scope": 1,
"no-console": 0,
"no-case-declarations": 0,
"quotes": ["error", "single"],
"eol-last": ["error", "always"]
"no-var": "error",
"no-prototype-builtins": "off",
"curly": ["error", "all"]
}
}
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
semi: true
trailingComma: "es5"
singleQuote: true
arrowParens: "avoid"
printWidth: 100
42 changes: 21 additions & 21 deletions Parse-Dashboard/Authentication.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';
var bcrypt = require('bcryptjs');
var csrf = require('csurf');
var passport = require('passport');
var LocalStrategy = require('passport-local').Strategy;
const bcrypt = require('bcryptjs');
const csrf = require('csurf');
const passport = require('passport');
const LocalStrategy = require('passport-local').Strategy;
const OTPAuth = require('otpauth')

/**
Expand All @@ -20,11 +20,11 @@ function Authentication(validUsers, useEncryptedPasswords, mountPath) {

function initialize(app, options) {
options = options || {};
var self = this;
const self = this;
passport.use('local', new LocalStrategy(
{passReqToCallback:true},
function(req, username, password, cb) {
var match = self.authenticate({
const match = self.authenticate({
name: username,
pass: password,
otpCode: req.body.otpCode
Expand All @@ -47,13 +47,13 @@ function initialize(app, options) {
});

passport.deserializeUser(function(username, cb) {
var user = self.authenticate({
const user = self.authenticate({
name: username
}, true);
cb(null, user);
});

var cookieSessionSecret = options.cookieSessionSecret || require('crypto').randomBytes(64).toString('hex');
const cookieSessionSecret = options.cookieSessionSecret || require('crypto').randomBytes(64).toString('hex');
const cookieSessionMaxAge = options.cookieSessionMaxAge;
app.use(require('connect-flash')());
app.use(require('body-parser').urlencoded({ extended: true }));
Expand All @@ -67,16 +67,16 @@ function initialize(app, options) {

app.post('/login',
csrf(),
(req,res,next) => {
let redirect = 'apps';
if (req.body.redirect) {
redirect = req.body.redirect.charAt(0) === '/' ? req.body.redirect.substring(1) : req.body.redirect
}
return passport.authenticate('local', {
successRedirect: `${self.mountPath}${redirect}`,
failureRedirect: `${self.mountPath}login${req.body.redirect ? `?redirect=${req.body.redirect}` : ''}`,
failureFlash : true
})(req, res, next)
(req,res,next) => {
let redirect = 'apps';
if (req.body.redirect) {
redirect = req.body.redirect.charAt(0) === '/' ? req.body.redirect.substring(1) : req.body.redirect
}
return passport.authenticate('local', {
successRedirect: `${self.mountPath}${redirect}`,
failureRedirect: `${self.mountPath}login${req.body.redirect ? `?redirect=${req.body.redirect}` : ''}`,
failureFlash : true
})(req, res, next)
},
);

Expand All @@ -100,13 +100,13 @@ function authenticate(userToTest, usernameOnly) {
let otpValid = true;

//they provided auth
let isAuthenticated = userToTest &&
const isAuthenticated = userToTest &&
//there are configured users
this.validUsers &&
//the provided auth matches one of the users
this.validUsers.find(user => {
let isAuthenticated = false;
let usernameMatches = userToTest.name == user.user;
const usernameMatches = userToTest.name == user.user;
if (usernameMatches && user.mfa && !usernameOnly) {
if (!userToTest.otpCode) {
otpMissingLength = user.mfaDigits || 6;
Expand All @@ -126,7 +126,7 @@ function authenticate(userToTest, usernameOnly) {
}
}
}
let passwordMatches = this.useEncryptedPasswords && !usernameOnly ? bcrypt.compareSync(userToTest.pass, user.pass) : userToTest.pass == user.pass;
const passwordMatches = this.useEncryptedPasswords && !usernameOnly ? bcrypt.compareSync(userToTest.pass, user.pass) : userToTest.pass == user.pass;
if (usernameMatches && (usernameOnly || passwordMatches)) {
isAuthenticated = true;
matchingUsername = user.user;
Expand Down
4 changes: 2 additions & 2 deletions Parse-Dashboard/CLI/mfa.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ const showInstructions = ({ app, username, passwordCopied, encrypt, config }) =>
`\n${getOrder()}. Make sure that "useEncryptedPasswords" is set to "true" in your dashboard configuration.` +
'\n You chose to generate an encrypted password for this user.' +
'\n Any existing users with non-encrypted passwords will require newly created, encrypted passwords.'
);
);
}
console.log(
'\n------------------------------------------------------------------------------\n'
Expand Down Expand Up @@ -198,7 +198,7 @@ module.exports = {
}
]);
const { algorithm, digits, period } = await getAlgorithm();
const secret =generateSecret({ app, username, algorithm, digits, period });
const secret = generateSecret({ app, username, algorithm, digits, period });
Object.assign(config, secret.config);
showQR(secret.config.url);
}
Expand Down
40 changes: 20 additions & 20 deletions Parse-Dashboard/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ const path = require('path');
const packageJson = require('package-json');
const csrf = require('csurf');
const Authentication = require('./Authentication.js');
var fs = require('fs');
const fs = require('fs');

const currentVersionFeatures = require('../package.json').parseDashboardFeatures;

var newFeaturesInLatestVersion = [];
let newFeaturesInLatestVersion = [];
packageJson('parse-dashboard', { version: 'latest', fullMetadata: true })
.then(latestPackage => {
if (latestPackage.parseDashboardFeatures instanceof Array) {
Expand All @@ -31,29 +31,29 @@ function getMount(mountPath) {
}

function checkIfIconsExistForApps(apps, iconsFolder) {
for (var i in apps) {
var currentApp = apps[i];
var iconName = currentApp.iconName;
var path = iconsFolder + '/' + iconName;
for (const i in apps) {
const currentApp = apps[i];
const iconName = currentApp.iconName;
const path = iconsFolder + '/' + iconName;

fs.stat(path, function(err) {
if (err) {
if ('ENOENT' == err.code) {// file does not exist
console.warn('Icon with file name: ' + iconName +' couldn\'t be found in icons folder!');
} else {
console.log(
'An error occurd while checking for icons, please check permission!');
}
if ('ENOENT' == err.code) {// file does not exist
console.warn('Icon with file name: ' + iconName + ' couldn\'t be found in icons folder!');
} else {
console.log(
'An error occurd while checking for icons, please check permission!');
}
} else {
//every thing was ok so for example you can read it and send it to client
//every thing was ok so for example you can read it and send it to client
}
} );
});
}
}

module.exports = function(config, options) {
options = options || {};
var app = express();
const app = express();
// Serve public files.
app.use(express.static(path.join(__dirname,'public')));

Expand All @@ -72,7 +72,7 @@ module.exports = function(config, options) {

// CSRF error handler
app.use(function (err, req, res, next) {
if (err.code !== 'EBADCSRFTOKEN') return next(err)
if (err.code !== 'EBADCSRFTOKEN') {return next(err)}

// handle CSRF token errors here
res.status(403)
Expand All @@ -81,8 +81,8 @@ module.exports = function(config, options) {

// Serve the configuration.
app.get('/parse-dashboard-config.json', function(req, res) {
let apps = config.apps.map((app) => Object.assign({}, app)); // make a copy
let response = {
const apps = config.apps.map((app) => Object.assign({}, app)); // make a copy
const response = {
apps: apps,
newFeaturesInLatestVersion: newFeaturesInLatestVersion,
};
Expand Down Expand Up @@ -159,7 +159,7 @@ module.exports = function(config, options) {
// running parse-dashboard from globally installed npm.
if (config.iconsFolder) {
try {
var stat = fs.statSync(config.iconsFolder);
const stat = fs.statSync(config.iconsFolder);
if (stat.isDirectory()) {
app.use('/appicons', express.static(config.iconsFolder));
//Check also if the icons really exist
Expand Down Expand Up @@ -213,7 +213,7 @@ module.exports = function(config, options) {
}
return res.redirect(`${mountPath}login`);
}
if (users && req.user && req.user.matchingUsername ) {
if (users && req.user && req.user.matchingUsername) {
res.append('username', req.user.matchingUsername);
}
res.send(`<!DOCTYPE html>
Expand Down
28 changes: 14 additions & 14 deletions Parse-Dashboard/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ module.exports = (options) => {
process.exit(-1);
}

let explicitConfigFileProvided = !!options.config;
const explicitConfigFileProvided = !!options.config;
let configFile = null;
let configFromCLI = null;
let configServerURL = options.serverURL || process.env.PARSE_DASHBOARD_SERVER_URL;
let configGraphQLServerURL = options.graphQLServerURL || process.env.PARSE_DASHBOARD_GRAPHQL_SERVER_URL;
let configMasterKey = options.masterKey || process.env.PARSE_DASHBOARD_MASTER_KEY;
let configAppId = options.appId || process.env.PARSE_DASHBOARD_APP_ID;
let configAppName = options.appName || process.env.PARSE_DASHBOARD_APP_NAME;
let configUserId = options.userId || process.env.PARSE_DASHBOARD_USER_ID;
let configUserPassword = options.userPassword || process.env.PARSE_DASHBOARD_USER_PASSWORD;
let configSSLKey = options.sslKey || process.env.PARSE_DASHBOARD_SSL_KEY;
let configSSLCert = options.sslCert || process.env.PARSE_DASHBOARD_SSL_CERT;
const configServerURL = options.serverURL || process.env.PARSE_DASHBOARD_SERVER_URL;
const configGraphQLServerURL = options.graphQLServerURL || process.env.PARSE_DASHBOARD_GRAPHQL_SERVER_URL;
const configMasterKey = options.masterKey || process.env.PARSE_DASHBOARD_MASTER_KEY;
const configAppId = options.appId || process.env.PARSE_DASHBOARD_APP_ID;
const configAppName = options.appName || process.env.PARSE_DASHBOARD_APP_NAME;
const configUserId = options.userId || process.env.PARSE_DASHBOARD_USER_ID;
const configUserPassword = options.userPassword || process.env.PARSE_DASHBOARD_USER_PASSWORD;
const configSSLKey = options.sslKey || process.env.PARSE_DASHBOARD_SSL_KEY;
const configSSLCert = options.sslCert || process.env.PARSE_DASHBOARD_SSL_CERT;

function handleSIGs(server) {
const signals = {
Expand Down Expand Up @@ -143,10 +143,10 @@ module.exports = (options) => {

const app = express();

if (allowInsecureHTTP || trustProxy || dev) app.enable('trust proxy');
if (allowInsecureHTTP || trustProxy || dev) {app.enable('trust proxy');}

config.data.trustProxy = trustProxy;
let dashboardOptions = { allowInsecureHTTP, cookieSessionSecret, dev, cookieSessionMaxAge };
const dashboardOptions = { allowInsecureHTTP, cookieSessionSecret, dev, cookieSessionMaxAge };
app.use(mountPath, parseDashboard(config.data, dashboardOptions));
let server;
if(!configSSLKey || !configSSLCert){
Expand All @@ -156,8 +156,8 @@ module.exports = (options) => {
});
} else {
// Start the server using SSL.
var privateKey = fs.readFileSync(configSSLKey);
var certificate = fs.readFileSync(configSSLCert);
const privateKey = fs.readFileSync(configSSLKey);
const certificate = fs.readFileSync(configSSLCert);

server = require('https').createServer({
key: privateKey,
Expand Down
2 changes: 1 addition & 1 deletion ci/nodeEngineCheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class NodeEngineCheck {
const dirents = await fs.readdir(basePath, { withFileTypes: true });
const validFiles = dirents.filter(d => d.name.toLowerCase() == 'package.json').map(d => path.join(basePath, d.name));
files.push(...validFiles);

// For each directory entry
for (const dirent of dirents) {
if (dirent.isDirectory()) {
Expand Down
12 changes: 12 additions & 0 deletions package-lock.json

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

18 changes: 17 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,13 @@
"eslint-plugin-jest": "27.0.4",
"eslint-plugin-react": "7.31.8",
"http-server": "14.0.0",
"husky": "8.0.3",
"jest": "29.1.2",
"jest-environment-jsdom": "29.1.2",
"madge": "5.0.1",
"marked": "4.0.10",
"null-loader": "4.0.1",
"prettier": "2.8.8",
"puppeteer": "18.0.5",
"react-test-renderer": "16.13.1",
"request": "2.88.2",
Expand All @@ -122,7 +124,9 @@
"pig": "http-server ./PIG -p 4041 -s & webpack --config webpack/PIG.config.js --progress --watch",
"build": "webpack --node-env=production --config webpack/production.config.js && webpack --config webpack/PIG.config.js",
"test": "jest",
"lint": "eslint . --ignore-path .gitignore --cache",
"lint": "eslint --ignore-path .gitignore --cache ./",
"lint:fix": "DEBUG=eslint:cli-engine eslint --ignore-path .gitignore --fix --cache ./",
"prettier": "prettier --write '{src,webpack}/**/*.js'",
"generate": "node scripts/generate.js",
"prepare": "webpack --config webpack/publish.config.js --progress",
"start": "node ./Parse-Dashboard/index.js",
Expand Down Expand Up @@ -152,5 +156,17 @@
"react-addons-test-utils",
"fbjs"
]
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"{src,webpack}/{**/*,*}.js": [
"prettier --write",
"eslint --fix --cache",
"git add"
]
}
}
2 changes: 1 addition & 1 deletion release.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ async function readFile(filePath) {

function getReleaseComment() {
const url = repositoryUrl + '/releases/tag/${nextRelease.gitTag}';
let comment = '🎉 This change has been released in version [${nextRelease.version}](' + url + ')';
const comment = '🎉 This change has been released in version [${nextRelease.version}](' + url + ')';
return comment;
}

Expand Down
Loading