From ed7cc4252331ac4427176c3abead92fba95cf8a5 Mon Sep 17 00:00:00 2001 From: Chidi Ekuma <7931750+ekumachidi@users.noreply.github.com> Date: Wed, 11 Dec 2024 19:10:09 +0000 Subject: [PATCH 1/3] Add GitHub Action for Code Linting This pull request introduces a GitHub Action workflow to automate the linting of various code types in the repo on each push and pull request. It add: - lint.yml to define the workflow - eslint.config.js to manage the rules for the js linting The workflow runs the following linters: - JavaScript: Uses ESLint to check for issues in JavaScript files. - HTML: Uses HTMLHint to lint HTML files. - CSS: Uses Stylelint to ensure proper CSS formatting. - Shell scripts: Uses ShellCheck to lint shell scripts. - C++: Uses Clang-Tidy to check C++ code for style and potential errors. By adding this workflow, we ensure consistent code quality and formatting across multiple languages in the repository. --- .github/workflows/lint.yml | 56 ++++++++++++++++++++++++++++++++++++++ eslint.config.js | 25 +++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 .github/workflows/lint.yml create mode 100644 eslint.config.js diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 00000000..25a4dc9e --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,56 @@ +name: Lint Code + +on: [push, pull_request] + +jobs: + lint: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Install ESLint globally + run: | + sudo apt-get update + sudo apt-get install -y eslint # Install ESLint globally + + - name: Install ShellCheck + run: | + sudo apt-get install -y shellcheck + + - name: Install Clang-Tidy + run: | + sudo apt-get install -y clang-tidy + + # - name: Install Perl and cpanm + # run: | + # sudo apt-get install -y perl + # sudo apt-get install -y cpanminus # Install cpanm tool + + # - name: Install missing Perl dependencies + # run: | + # sudo cpanm Module::Pluggable # Install the missing dependency + # sudo cpanm --installdeps Perl::Critic # Install all dependencies for Perl::Critic + + # - name: Install Perl::Critic + # run: | + # sudo cpanm Perl::Critic # Install Perl::Critic module + + - name: Lint JavaScript + run: npx eslint . + + - name: Lint HTML + run: npx htmlhint . + + - name: Lint CSS + run: npx stylelint "**/*.css" + + - name: Lint Shell scripts + run: shellcheck **/*.sh + + - name: Lint C++ code + run: clang-tidy **/*.cpp + + # - name: Lint Perl + # run: perlcritic **/*.pl diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 00000000..852856d6 --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,25 @@ +// eslint.config.js +module.exports = [ + { + languageOptions: { + globals: { + // Define any global variables here (e.g., for browsers) + window: 'readonly', + document: 'readonly', + }, + parserOptions: { + ecmaVersion: 12, // ES2021 + sourceType: 'module', // Enable ES6 modules + }, + }, + rules: { + 'no-console': 'warn', // Warn on console statements + 'semi': ['error', 'always'], // Enforce semicolons + 'quotes': ['error', 'single'], // Enforce single quotes + 'eqeqeq': 'error', // Enforce strict equality (===) + 'curly': 'error', // Enforce curly braces for control statements + 'no-unused-vars': 'warn', // Warn about unused variables + 'no-magic-numbers': 'off', // Optional: disable rule for magic numbers if you want + }, + }, +]; From d549da576f1098caf4ac559a23a22ee8dd0d638a Mon Sep 17 00:00:00 2001 From: Chidi Ekuma <7931750+ekumachidi@users.noreply.github.com> Date: Thu, 12 Dec 2024 18:53:10 +0000 Subject: [PATCH 2/3] Enhance GitHub Actions workflow by adding separate linting jobs for JavaScript, HTML, CSS, Shell, and C++ code --- .github/workflows/lint.yml | 68 +++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 27 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 25a4dc9e..abc74aa5 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -3,9 +3,8 @@ name: Lint Code on: [push, pull_request] jobs: - lint: + lint_js: runs-on: ubuntu-latest - steps: - name: Checkout code uses: actions/checkout@v2 @@ -15,42 +14,57 @@ jobs: sudo apt-get update sudo apt-get install -y eslint # Install ESLint globally - - name: Install ShellCheck - run: | - sudo apt-get install -y shellcheck - - - name: Install Clang-Tidy - run: | - sudo apt-get install -y clang-tidy - - # - name: Install Perl and cpanm - # run: | - # sudo apt-get install -y perl - # sudo apt-get install -y cpanminus # Install cpanm tool - - # - name: Install missing Perl dependencies - # run: | - # sudo cpanm Module::Pluggable # Install the missing dependency - # sudo cpanm --installdeps Perl::Critic # Install all dependencies for Perl::Critic - - # - name: Install Perl::Critic - # run: | - # sudo cpanm Perl::Critic # Install Perl::Critic module - - name: Lint JavaScript run: npx eslint . + lint_html: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Install HTMLHint globally + run: | + sudo npm install -g htmlhint + - name: Lint HTML run: npx htmlhint . + lint_css: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Install Stylelint globally + run: | + sudo npm install -g stylelint + - name: Lint CSS run: npx stylelint "**/*.css" + lint_shell: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Install ShellCheck globally + run: | + sudo apt-get install -y shellcheck + - name: Lint Shell scripts run: shellcheck **/*.sh + lint_cpp: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Install Clang-Tidy globally + run: | + sudo apt-get install -y clang-tidy + - name: Lint C++ code run: clang-tidy **/*.cpp - - # - name: Lint Perl - # run: perlcritic **/*.pl From b5496176e19d94c9719de93272025b16f08b23f0 Mon Sep 17 00:00:00 2001 From: Chidi Ekuma <7931750+ekumachidi@users.noreply.github.com> Date: Thu, 12 Dec 2024 19:04:23 +0000 Subject: [PATCH 3/3] Add HTML Tidy job to lint and fix HTML files in GitHub Actions workflow --- .github/workflows/lint.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index abc74aa5..dc8558d0 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -30,6 +30,21 @@ jobs: - name: Lint HTML run: npx htmlhint . + fix_html: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Install HTML Tidy globally + run: | + sudo apt-get update + sudo apt-get install -y tidy + + - name: Lint and Fix HTML files + run: | + tidy -qe **/*.html + lint_css: runs-on: ubuntu-latest steps: