diff --git a/.eslintrc.json b/.eslintrc.json index 0ec39af..7f86f6f 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -26,6 +26,7 @@ "no-plusplus": "error", "eqeqeq": ["error", "always"], "quotes": ["error", "double"], - "semi": ["error", "always"] + "semi": ["error", "always"], + "space-before-function-paren": ["error", "never"] } } diff --git a/.github/lint.yml b/.github/workflows/lint.yml similarity index 55% rename from .github/lint.yml rename to .github/workflows/lint.yml index db4d586..828cb6a 100644 --- a/.github/lint.yml +++ b/.github/workflows/lint.yml @@ -1,17 +1,18 @@ +name: linter + on: - push: - branches: - - master - - main pull_request: - branches: - - "*" + branches: [main] + jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 16 - name: Install Dependencies run: npm install diff --git a/.prettierrc b/.prettierrc index f0a8513..48f612c 100644 --- a/.prettierrc +++ b/.prettierrc @@ -2,5 +2,6 @@ "tabWidth": 2, "useTabs": false, "semi": true, - "singleQuote": false + "singleQuote": false, + "trailingComma": "none" } diff --git a/package.json b/package.json index d7610c1..d7a5e16 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "description": "A minimalist approach toward git commits to keep things simple.", "main": "./bin/index.js", "scripts": { - "lint": "eslint ." + "lint": "eslint .", + "fix": "eslint . --fix" }, "bin": { "mct": "bin/index.js" diff --git a/src/cli.js b/src/cli.js index 7390c32..5dd084d 100644 --- a/src/cli.js +++ b/src/cli.js @@ -6,17 +6,13 @@ import { getStagedFiles, checkIfRepoisGit, getUnstagedFiles, - stageFiles, + stageFiles } from "./commands.js"; -function logOption(title, description) { - return chalk.bgWhite(title) + " - " + description; -} - async function cli() { const [isGit, stagedFiles] = await Promise.all([ checkIfRepoisGit(), - getStagedFiles(), + getStagedFiles() ]); if (isGit && !stagedFiles) { await promptToCommit(); @@ -61,15 +57,15 @@ const promptToCommit = async () => { if (styledList.length < 1) { console.log(chalk.bgRed("No changes made since last commit!")); } - return await inquirer + await inquirer .prompt([ { name: "list", message: "Select the files you want to add with, and use (CTRL + D to exit)", type: "checkbox", - choices: styledList, - }, + choices: styledList + } ]) .then((answer) => { if (answer.list.length < 1) { @@ -92,7 +88,7 @@ const promptToCommit = async () => { console.log(chalk.bgGreenBright("✅ Files Added")); addCommit(); }) - .catch((err) => { + .catch(() => { console.log( chalk.bgRed("⛔️ Oops, that was not supposed to happen") + chalk.bgGrey("If that happens again, please raise an issue") @@ -101,8 +97,8 @@ const promptToCommit = async () => { }); }; -const addCommit = async () => { - return await inquirer +async function addCommit() { + await inquirer .prompt([ { name: "type", @@ -118,20 +114,20 @@ const addCommit = async () => { "📝 docs", "🎨 style", "🛠 config", - "📦 misc", - ], + "📦 misc" + ] }, { name: "message", message: "Write a commit message ✍️ : ", - type: "input", - }, + type: "input" + } ]) .then((answer) => { const message = `${answer.type}: ${answer.message}`; console.log("\n"); - if (answer.message == "") { + if (answer.message === "") { console.log(chalk.bgRed("⛔️ Message can't be empty")); process.exit(0); } else if (!answer.message.includes(" ")) { @@ -151,6 +147,6 @@ const addCommit = async () => { commitFiles(message); }); -}; +} export default cli; diff --git a/src/commands.js b/src/commands.js index 2af3c58..ba5b704 100644 --- a/src/commands.js +++ b/src/commands.js @@ -5,7 +5,7 @@ import { logExec } from "./helper.js"; export function checkIfRepoisGit() { return new Promise((resolve, reject) => { exec("git rev-parse --is-inside-work-tree", (err, stdout, stderr) => { - if (stdout == "true\n") resolve(stdout); + if (stdout === "true\n") resolve(stdout); if (stderr.includes("not a git repository")) { console.log("\n\n"); console.log(