diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..87ea188 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,18 @@ +module.exports = { + env: { + browser: true, + commonjs: true, + es6: true, + node: true, + }, + extends: "eslint:recommended", + ignorePatterns: ["dist/"], + globals: { + Atomics: "readonly", + SharedArrayBuffer: "readonly", + }, + parserOptions: { + ecmaVersion: 2018, + }, + rules: {}, +}; diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index ecf3031..256291e 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -5,10 +5,37 @@ on: types: [opened, synchronize] push: branches: - - master - main + workflow_dispatch: jobs: + linting: + runs-on: ubuntu-latest + if: github.event_name == 'pull_request' + + strategy: + matrix: + node-version: [22.16] + + steps: + - uses: actions/checkout@v4 + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + + - name: Run npm ci + run: npm ci + + - name: Run npm prettier + continue-on-error: true + run: | + ./node_modules/.bin/prettier --check . || echo "::warning::Prettier found formatting issues. Fix it locally by running './node_modules/.bin/prettier --write .'" + + - name: Run ESLint + run: ./node_modules/.bin/eslint --ext .js . + unit-tests: runs-on: ubuntu-latest @@ -38,7 +65,8 @@ jobs: browserstack: runs-on: ubuntu-latest - needs: unit-tests + needs: [unit-tests, linting] + if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch' strategy: matrix: @@ -60,16 +88,6 @@ jobs: - uses: actions/checkout@v4 - - name: Prettier Action on PR - uses: creyD/prettier_action@v4.5 - with: - dry: true - prettier_options: "--write {**/*,*}.{js,hbs,html,json,md,yml,css,scss} !.github/workflows/**/* !dist/**/*" - commit_message: "Run prettier via GitHub Action" - file_pattern: "." - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v4 with: diff --git a/package.json b/package.json index 2809e6a..d2b3294 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "playground": "./playground.sh", "watch": "node_modules/.bin/nodemon compile.js --ignore dist", "build": "node compile.js", + "lint": "./node_modules/.bin/eslint --ext .js .", "pretest": "npm run build -- testing", "test": "node -r dotenv/config ./test/index.js", "posttest": "npm run build", diff --git a/src/auto-events.js b/src/auto-events.js index af554a9..a61a614 100644 --- a/src/auto-events.js +++ b/src/auto-events.js @@ -73,7 +73,7 @@ if (typeof optionsLink === "undefined") log("options object not found, please specify", "warn"); - window.saAutomatedLink = function saAutomatedLink(element, type) { + var saAutomatedLink = function saAutomatedLink(element, type) { try { if (!element) return log("no element found"); var sent = false; @@ -146,6 +146,8 @@ } }; + window.saAutomatedLink = saAutomatedLink; + function collectLink(link, onclick) { var collect = false;