Skip to content

Commit

Permalink
refactor: improve lint (madlabsinc#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Oct 4, 2019
1 parent 31a4653 commit 835de5d
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 32 deletions.
4 changes: 2 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = {
},
parserOptions: {
sourceType: "module",
ecmaVersion: "2017",
ecmaVersion: "2018",
allowImportExportEverywhere: false,
ecmaFeatures: {
globalReturn: false,
Expand All @@ -26,4 +26,4 @@ module.exports = {
],
eqeqeq: ['error', 'always'], // adding some custom ESLint rules
},
};
};
44 changes: 21 additions & 23 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,40 @@ const submitTask = require('../src/commands/submit');
program.version(version).usage('<command> [options]');

program
.command('init')
.description('Initialize challenges')
.action(initTasks);
.command('init')
.description('Initialize challenges')
.action(initTasks);

program
.command('submit')
.description('Submits current task')
.action(submitTask);
.command('submit')
.description('Submits current task')
.action(submitTask);

program
.command('fetchtask <key>')
.description('Fetches any task as per the key supplied')
.action(fetchTask);
.command('fetchtask <key>')
.description('Fetches any task as per the key supplied')
.action(fetchTask);

program
.command('showkeys')
.description('Shows keys of all the completed tasks')
.action(showKeys);
.command('showkeys')
.description('Shows keys of all the completed tasks')
.action(showKeys);

program
.command('showcommands')
.description('Shows all commands available')
.action(showCommands);
.command('showcommands')
.description('Shows all commands available')
.action(showCommands);

// Validates any random command fired in
program
.arguments('<command>')
.action((cmd) => {
program.outputHelp();
console.log(` ` + chalk.red(`\n Unknown command ${chalk.yellow(cmd)}.`));
console.log();
program.arguments('<command>').action(cmd => {
program.outputHelp();
console.log(` ` + chalk.red(`\n Unknown command ${chalk.yellow(cmd)}.`));
console.log();
});

program.parse(process.argv);

// Outputs help if no argument is provided
if(!program.args.length){
program.help();
if (!program.args.length) {
program.help();
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"test": "mocha test/index.js",
"docs:dev": "vuepress dev docs",
"docs:build": "vuepress build docs",
"lint": "eslint ./src",
"lint:fix": "eslint --fix ./src"
"lint": "eslint src bin",
"lint:fix": "eslint --fix src bin"
},
"husky": {
"hooks": {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const {
initializeGHWorkFlow,
} = require('../utils/github');

const validateInput = require('../utils/validate');
const validate = require('../utils/validate');

// Key for the very first task
let key = '5e06b81de9ac43218a974785ffce8146';
Expand Down Expand Up @@ -103,7 +103,7 @@ const initTasks = async () => {
name: 'userName',
type: 'input',
message: "What's your name:-",
validate: validateInput,
validate,
},
]);

Expand Down
6 changes: 5 additions & 1 deletion src/commands/submit.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ const checkSolution = async (submittedFileContent, solutionFileContent) => {
taskCount += 1;
keys.push(generatedKey);

userConfig = Object.assign({}, userConfig, { taskCount, keys });
userConfig = {
...userConfig,
taskCount,
keys,
};
fs.writeFileSync('./config.json', JSON.stringify(userConfig));

await makeLocalCommit(taskCount);
Expand Down
4 changes: 2 additions & 2 deletions src/utils/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const shell = require('shelljs');

const execAsync = promisify(shell.exec);

const validateInput = require('../utils/validate');
const validate = require('../utils/validate');

// Global reference to the GitHub username.
let GHUserName;
Expand All @@ -25,7 +25,7 @@ const initializeGHWorkFlow = async () => {
name: 'userName',
message: 'GitHub username:-',
type: 'input',
validate: validateInput,
validate,
});

// Holding global reference to the GitHub username.
Expand Down

0 comments on commit 835de5d

Please sign in to comment.