diff --git a/.github/workflows/eslint.yml b/.github/workflows/eslint.yml new file mode 100644 index 00000000..deffd736 --- /dev/null +++ b/.github/workflows/eslint.yml @@ -0,0 +1,26 @@ +name: ESLint + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +permissions: + contents: read + +jobs: + eslint: + name: ESLint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v4 + - name: Set up Node + uses: actions/setup-node@v4 + with: + node-version: '18' + - name: Install node dependencies + run: pnpm install + - name: Run JavaScript linter + run: pnpm eslint diff --git a/Rakefile b/Rakefile index 0064bcb9..d5f5d52a 100644 --- a/Rakefile +++ b/Rakefile @@ -11,7 +11,7 @@ task default: [:rubocop, 'test:ruby'] require 'rake/testtask' namespace :test do desc %(Run all tests) - task all: [:rubocop, 'test:ruby', 'test:js'] + task all: [:rubocop, :lint_javascript, 'test:ruby', 'test:js'] desc %(Test Ruby code) Rake::TestTask.new(:ruby) do |test| @@ -53,6 +53,11 @@ namespace :test do end end +desc %(Lint JavaScript files) +task :lint_javascript do + run_pnpm_script 'eslint' +end + desc %(Regenerate JavaScript files) task :regenerate_javascript do run_pnpm_script 'build' diff --git a/dist/client-side-validations.esm.js b/dist/client-side-validations.esm.js index 455680f7..990a14ef 100644 --- a/dist/client-side-validations.esm.js +++ b/dist/client-side-validations.esm.js @@ -697,7 +697,7 @@ function isAMD() { return typeof define === 'function' && define.amd; // eslint-disable-line no-undef } function isCommonJS() { - return (typeof exports === "undefined" ? "undefined" : _typeof(exports)) === 'object' && typeof module !== 'undefined'; // eslint-disable-line no-undef + return (typeof exports === "undefined" ? "undefined" : _typeof(exports)) === 'object' && typeof module !== 'undefined'; } export { ClientSideValidations as default }; diff --git a/dist/client-side-validations.js b/dist/client-side-validations.js index 583cfbd6..86a45d1e 100644 --- a/dist/client-side-validations.js +++ b/dist/client-side-validations.js @@ -701,7 +701,7 @@ return typeof define === 'function' && define.amd; // eslint-disable-line no-undef } function isCommonJS() { - return (typeof exports === "undefined" ? "undefined" : _typeof(exports)) === 'object' && typeof module !== 'undefined'; // eslint-disable-line no-undef + return (typeof exports === "undefined" ? "undefined" : _typeof(exports)) === 'object' && typeof module !== 'undefined'; } return ClientSideValidations; diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 00000000..2bd9b289 --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,13 @@ +import neostandard from 'neostandard' + +export default [ + { + ignores: [ + 'coverage/**/*.js', + 'dist/**/*.js', + 'test/**/*.js', + 'vendor/**/*.js', + ] + }, + ...neostandard() +] diff --git a/package.json b/package.json index ee2a33ae..bcd55136 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ }, "homepage": "https://github.com/DavyJonesLocker/client_side_validations", "scripts": { - "build": "standard --verbose && rollup -c", + "build": "rollup -c", "test": "test/javascript/run-qunit.mjs" }, "devDependencies": { @@ -27,10 +27,11 @@ "@rollup/plugin-babel": "^6.0.4", "@rollup/plugin-node-resolve": "^15.3.0", "chrome-launcher": "^1.1.2", + "eslint": "^9.12.0", + "neostandard": "^0.11.6", "puppeteer-core": "^23.5.3", "rollup": "^4.24.0", - "rollup-plugin-copy": "^3.5.0", - "standard": "^17.1.2" + "rollup-plugin-copy": "^3.5.0" }, "peerDependencies": { "jquery": ">= 1.12.4 < 4.0.0" diff --git a/src/index.js b/src/index.js index d8cbfc96..0a810e65 100644 --- a/src/index.js +++ b/src/index.js @@ -216,7 +216,7 @@ function isAMD () { } function isCommonJS () { - return typeof exports === 'object' && typeof module !== 'undefined' // eslint-disable-line no-undef + return typeof exports === 'object' && typeof module !== 'undefined' } export default ClientSideValidations diff --git a/test/javascript/run-qunit.mjs b/test/javascript/run-qunit.mjs index 7958366b..075c460e 100755 --- a/test/javascript/run-qunit.mjs +++ b/test/javascript/run-qunit.mjs @@ -25,9 +25,11 @@ export default (async () => { return new Promise(resolve => setTimeout(resolve, ms)) } + let browser + try { const chromeExecutablePath = chromeLauncher.Launcher.getInstallations()[0] - const browser = await puppeteer.launch({ executablePath: chromeExecutablePath, headless: 'new' }) + browser = await puppeteer.launch({ executablePath: chromeExecutablePath, headless: 'new' }) const page = await browser.newPage() // Attach to browser console log events, and log to node console diff --git a/vendor/assets/javascripts/rails.validations.js b/vendor/assets/javascripts/rails.validations.js index 583cfbd6..86a45d1e 100644 --- a/vendor/assets/javascripts/rails.validations.js +++ b/vendor/assets/javascripts/rails.validations.js @@ -701,7 +701,7 @@ return typeof define === 'function' && define.amd; // eslint-disable-line no-undef } function isCommonJS() { - return (typeof exports === "undefined" ? "undefined" : _typeof(exports)) === 'object' && typeof module !== 'undefined'; // eslint-disable-line no-undef + return (typeof exports === "undefined" ? "undefined" : _typeof(exports)) === 'object' && typeof module !== 'undefined'; } return ClientSideValidations;