diff --git a/.editorconfig b/.editorconfig index ef2062c5..cbcd4788 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,3 +1,11 @@ +root = true + +[*.{js,ts,json,md}] +charset = utf-8 +end_of_line = lf +indent_style = space +indent_size = 2 +insert_final_newline = true # editorconfig.org root = true diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 00000000..38950696 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,22 @@ +{ + "root": true, + "env": { + "node": true, + "mocha": true, + "es6": true + }, + "extends": [ + "eslint:recommended", + "plugin:import/errors", + "plugin:import/warnings" + ], + "parserOptions": { + "ecmaVersion": 2019, + "sourceType": "module" + }, + "rules": { + "no-unused-vars": ["warn", { "args": "none" }], + "no-console": "off", + "import/no-unresolved": "off" + } +} diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 00000000..c82355e7 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,23 @@ +--- +name: Bug report +about: Create a report to help us improve +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Run '...' +3. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Environment (please complete the following information):** +- OS: [e.g. Windows 10] +- Node: [e.g. 18.x] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..a71c6d0c --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,29 @@ +name: CI + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [16.x, 18.x] + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Use Node.js + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + + - name: Install dependencies + run: npm ci + + - name: Run tests + run: npm test diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..4ea0afbb --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,10 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +## Unreleased + +- Add CI workflow +- Add ESLint and EditorConfig +- Add CONTRIBUTING and issue template +- Add fast-test and ci-test scripts diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..b8ad81b4 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,10 @@ +# Contributing + +Thanks for your interest in contributing to node-sql-parser. A few guidelines: + +- Fork the repo and open a branch for your change. +- Run tests locally with `npm test` and keep lint passing with `npm run lint`. +- Include unit tests for bug fixes and new features. +- Open a PR and reference an issue if applicable. + +If you're new, check open issues labeled `good first issue`. diff --git a/README.md b/README.md index 235b1951..b8532a43 100644 --- a/README.md +++ b/README.md @@ -351,6 +351,22 @@ parser.whiteListCheck(sql, whiteColumnList, opt) // if check failed, an error wo ## :kissing_heart: Acknowledgement +## Developer quickstart + +Run tests locally: + +```bash +npm ci +npm test +``` + +For a faster local smoke-run during development: + +```bash +npm run fast-test +``` + + This project is inspired by the SQL parser [flora-sql-parser](https://github.com/godmodelabs/flora-sql-parser) module. ## License diff --git a/package.json b/package.json index 52f8ad82..f15705eb 100644 --- a/package.json +++ b/package.json @@ -5,11 +5,13 @@ "main": "index.js", "types": "types.d.ts", "scripts": { - "start": "webpack --config webpack.config.js", - "build": "npm run lint && npm run compile && webpack --config webpack.config.js --mode production", - "test": "npm run lint && mochapack --reporter-option maxDiffSize=1000000 \"test/**/*.spec.js\"", - "lint": "eslint src", - "compile": "babel src -d lib", + "start": "webpack --config webpack.config.js", + "build": "npm run lint && npm run compile && webpack --config webpack.config.js --mode production", + "test": "npm run lint && mochapack --reporter-option maxDiffSize=1000000 \"test/**/*.spec.js\"", + "fast-test": "mocha \"test/**/*(select|insert|update|delete|util).spec.js\" --reporter spec", + "ci-test": "npm run lint && npm run fast-test", + "lint": "eslint src", + "compile": "babel src -d lib", "coverLocal": "cross-env NODE_ENV=coverage nyc --reporter=lcov --reporter=text npm run test", "cover:run": "cross-env NODE_ENV=coverage nyc --reporter=text-lcov npm run test", "cover": "npm run cover:run && nyc report --reporter=text-lcov | coveralls",