From 8c02eb2be039b66c398e5e8fd62df58e9ecd06eb Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Sat, 6 Feb 2021 09:59:25 -0600 Subject: [PATCH 01/35] Rename master branch to main --- .publishrc | 2 +- README.md | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.publishrc b/.publishrc index 380b0a3..b90ef3a 100644 --- a/.publishrc +++ b/.publishrc @@ -4,7 +4,7 @@ "uncommittedChanges": true, "untrackedFiles": true, "sensitiveData": true, - "branch": "master", + "branch": "main", "gitTag": true }, "confirm": true, diff --git a/README.md b/README.md index 27e320a..0afcf7f 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,8 @@ [![npm package](https://badge.fury.io/js/regex-to-strings.svg)](https://badge.fury.io/js/regex-to-strings) ![node version](https://img.shields.io/node/v/regex-to-strings.svg) ![npm type definitions](https://img.shields.io/npm/types/regex-to-strings) -[![Build Status](https://travis-ci.org/wimpyprogrammer/regex-to-strings.svg?branch=master)](https://travis-ci.org/wimpyprogrammer/regex-to-strings) -[![codecov](https://codecov.io/gh/wimpyprogrammer/regex-to-strings/branch/master/graph/badge.svg)](https://codecov.io/gh/wimpyprogrammer/regex-to-strings) +[![Build Status](https://travis-ci.org/wimpyprogrammer/regex-to-strings.svg?branch=main)](https://travis-ci.org/wimpyprogrammer/regex-to-strings) +[![codecov](https://codecov.io/gh/wimpyprogrammer/regex-to-strings/branch/main/graph/badge.svg)](https://codecov.io/gh/wimpyprogrammer/regex-to-strings) [![Known Vulnerabilities](https://snyk.io/test/github/wimpyprogrammer/regex-to-strings/badge.svg)](https://snyk.io/test/github/wimpyprogrammer/regex-to-strings) Generate strings that match a Regular Expression pattern. Efficiently generate all possible matches, or only the quantity you need. @@ -108,7 +108,7 @@ console.log(strings); // ['6', '5', '0', '2', '7', '9', '4', '3', '1', '8'] `regex-to-strings` uses [`regexp-tree`](https://www.npmjs.com/package/regexp-tree) to parse your Regular Expression, and so the Regular Expression syntax you can use is largely determined by that library. If your pattern is not recognized by `regex-to-strings`, [try parsing it with `regexp-tree`](https://astexplorer.net/#/gist/4ea2b52f0e546af6fb14f9b2f5671c1c/39b55944da3e5782396ffa1fea3ba68d126cd394) to see if the syntax is supported. -`regex-to-strings` also includes [extensive positive **and** negative tests](https://github.com/wimpyprogrammer/regex-to-strings/blob/master/src/pattern.spec.ts) that track which Regular Expression features are supported. +`regex-to-strings` also includes [extensive positive **and** negative tests](https://github.com/wimpyprogrammer/regex-to-strings/blob/main/src/pattern.spec.ts) that track which Regular Expression features are supported. ### Regular Expressions with unbounded repetition From 18f005974391f402ed6dd56cd92bebd1e18b3232 Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Sat, 6 Feb 2021 10:10:01 -0600 Subject: [PATCH 02/35] Group scripts with npm-run-all --- package.json | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 774c89a..fb900ff 100644 --- a/package.json +++ b/package.json @@ -25,15 +25,17 @@ "node": ">=10" }, "scripts": { - "build": "npm run clean && babel src -d lib --extensions '.js,.ts' --ignore '**/*.spec.js','**/*.spec.ts' && npm run build-types", - "build-demo": "npm run clean-demo && webpack --config demo/webpack.config.js", - "build-types": "tsc -p ./tsconfig.release-types.json", - "clean": "rimraf lib/*", - "clean-demo": "rimraf demo/lib/*", + "build": "run-s clean:* build:*", + "build:src": "babel src -d lib --extensions '.js,.ts' --ignore '**/*.spec.js','**/*.spec.ts'", + "build:demo": "webpack --config demo/webpack.config.js", + "build:types": "tsc -p ./tsconfig.release-types.json", + "clean:src": "rimraf lib/*", + "clean:demo": "rimraf demo/lib/*", "format": "prettier --write '{src,demo/src}/**'", - "lint": "tsc -p ./tsconfig.release.json && eslint . --ext .js,.ts --report-unused-disable-directives --parser-options=project:./tsconfig.release.json", - "lint-demo": "tsc -p ./demo/tsconfig.json && eslint . --ext .js,.ts --report-unused-disable-directives --parser-options=project:./demo/tsconfig.json", - "lint-tests": "tsc -p ./tsconfig.test.json && eslint . --ext .js,.ts --report-unused-disable-directives --parser-options=project:./tsconfig.test.json", + "lint": "run-s lint:*", + "lint:src": "tsc -p ./tsconfig.release.json && eslint . --ext .js,.ts --report-unused-disable-directives --parser-options=project:./tsconfig.release.json", + "lint:demo": "tsc -p ./demo/tsconfig.json && eslint . --ext .js,.ts --report-unused-disable-directives --parser-options=project:./demo/tsconfig.json", + "lint:tests": "tsc -p ./tsconfig.test.json && eslint . --ext .js,.ts --report-unused-disable-directives --parser-options=project:./tsconfig.test.json", "precommit": "pretty-quick --staged", "prepublish": "npx publish-please guard", "publish-please": "npx publish-please", @@ -66,6 +68,7 @@ "jest": "^26.4.2", "jest-when": "^2.7.0", "node-sass": "^4.12.0", + "npm-run-all": "^4.1.5", "prettier": "1.18.2", "pretty-quick": "1.7.0", "rimraf": "^2.7.1", From 67093f893423630e9199d54530dce7639cc95e6f Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Sat, 6 Feb 2021 11:57:17 -0600 Subject: [PATCH 03/35] Begin GitHub Actions workflow to run tests --- .github/workflows/tests.yml | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..5d40114 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,37 @@ +name: Tests + +on: + push: + branches: [main, develop] + pull_request: + branches: [main, develop] + schedule: + # 00:00 on Saturdays + - cron: '0 0 * * SAT' + workflow_dispatch: + +jobs: + test: + name: Test + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + node-version: [10.x, 14.x] + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + with: + fetch-depth: '2' + + - name: Test on Node ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + + - run: npm install + - run: npm run lint + - run: npm run build + - run: npm run test From 40ad0354f7bbf98f9da274817dfb577fe563957b Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Sat, 6 Feb 2021 11:57:43 -0600 Subject: [PATCH 04/35] Upload test report to Codecov --- .github/workflows/tests.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 5d40114..0f9ad2d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -35,3 +35,8 @@ jobs: - run: npm run lint - run: npm run build - run: npm run test + + - name: Upload test coverage report to Codecov + uses: codecov/codecov-action@v1 + with: + fail_ci_if_error: true From f6e0a12dd6add5bbe791f8dbea09000d88fd7928 Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Sat, 6 Feb 2021 13:19:50 -0600 Subject: [PATCH 05/35] Add Snyk security test to test workflow --- .github/workflows/tests.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0f9ad2d..dfc6c1d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -40,3 +40,8 @@ jobs: uses: codecov/codecov-action@v1 with: fail_ci_if_error: true + + - name: Run Snyk to check for vulnerabilities + uses: snyk/actions/node@master + env: + SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} From 4f5766027173b1df86af2d11db923f02772ef0f4 Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Sat, 6 Feb 2021 13:24:13 -0600 Subject: [PATCH 06/35] Scan code for vulnerabilities with CodeQL --- .github/workflows/security-scan.yml | 36 +++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/security-scan.yml diff --git a/.github/workflows/security-scan.yml b/.github/workflows/security-scan.yml new file mode 100644 index 0000000..b5efb06 --- /dev/null +++ b/.github/workflows/security-scan.yml @@ -0,0 +1,36 @@ +name: Security Scan + +on: + push: + branches: [main, develop] + pull_request: + branches: [main, develop] + schedule: + # 10:17 on Fridays + - cron: '17 10 * * 5' + workflow_dispatch: + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + language: ['javascript'] + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Initialize CodeQL + uses: github/codeql-action/init@v1 + with: + languages: ${{ matrix.language }} + + - name: Autobuild + uses: github/codeql-action/autobuild@v1 + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v1 From 7e90659a5b72e7db3969f6462eaac6c02820a5d4 Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Sat, 6 Feb 2021 13:26:34 -0600 Subject: [PATCH 07/35] Delete TravisCI integration --- .travis.yml | 9 --------- README.md | 1 - package.json | 3 +-- 3 files changed, 1 insertion(+), 12 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 3f43eb2..0000000 --- a/.travis.yml +++ /dev/null @@ -1,9 +0,0 @@ -language: node_js -node_js: - - 'node' - - '10' -script: - - npm run travisci -cache: - directories: - - node_modules diff --git a/README.md b/README.md index 0afcf7f..11cc5e3 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,6 @@ [![npm package](https://badge.fury.io/js/regex-to-strings.svg)](https://badge.fury.io/js/regex-to-strings) ![node version](https://img.shields.io/node/v/regex-to-strings.svg) ![npm type definitions](https://img.shields.io/npm/types/regex-to-strings) -[![Build Status](https://travis-ci.org/wimpyprogrammer/regex-to-strings.svg?branch=main)](https://travis-ci.org/wimpyprogrammer/regex-to-strings) [![codecov](https://codecov.io/gh/wimpyprogrammer/regex-to-strings/branch/main/graph/badge.svg)](https://codecov.io/gh/wimpyprogrammer/regex-to-strings) [![Known Vulnerabilities](https://snyk.io/test/github/wimpyprogrammer/regex-to-strings/badge.svg)](https://snyk.io/test/github/wimpyprogrammer/regex-to-strings) diff --git a/package.json b/package.json index fb900ff..4658c88 100644 --- a/package.json +++ b/package.json @@ -40,8 +40,7 @@ "prepublish": "npx publish-please guard", "publish-please": "npx publish-please", "publish-please-prereqs": "npm run lint && npm run test && npm run build", - "test": "jest --coverage", - "travisci": "npm run lint && npm run test && codecov && npx snyk test" + "test": "jest --coverage" }, "devDependencies": { "@babel/cli": "^7.5.5", From c8b30f1bdf4d73390cb619c2071eac4be4789a31 Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Sat, 6 Feb 2021 13:39:14 -0600 Subject: [PATCH 08/35] Add Tests workflow badge to README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 11cc5e3..46c65f4 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ [![npm package](https://badge.fury.io/js/regex-to-strings.svg)](https://badge.fury.io/js/regex-to-strings) ![node version](https://img.shields.io/node/v/regex-to-strings.svg) ![npm type definitions](https://img.shields.io/npm/types/regex-to-strings) +![Tests](https://github.com/wimpyprogrammer/regex-to-strings/workflows/Tests/badge.svg) [![codecov](https://codecov.io/gh/wimpyprogrammer/regex-to-strings/branch/main/graph/badge.svg)](https://codecov.io/gh/wimpyprogrammer/regex-to-strings) [![Known Vulnerabilities](https://snyk.io/test/github/wimpyprogrammer/regex-to-strings/badge.svg)](https://snyk.io/test/github/wimpyprogrammer/regex-to-strings) From ed681236910793d5a814f39d7f06ae4db2e8459f Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Sat, 6 Feb 2021 14:44:19 -0600 Subject: [PATCH 09/35] Specify *.yml file indentation --- .editorconfig | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.editorconfig b/.editorconfig index 3d7bfe4..3b08abd 100644 --- a/.editorconfig +++ b/.editorconfig @@ -9,6 +9,10 @@ end_of_line = lf insert_final_newline = true indent_style = tab +[*.yml] +indent_style = space +indent_size = 2 + [{package.json,package-lock.json}] indent_style = space indent_size = 2 From fec40219eba6496b7dfc1363fa8f614d82647ad1 Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Sat, 6 Feb 2021 14:45:07 -0600 Subject: [PATCH 10/35] Test packaged module with testpack-cli --- .github/workflows/tests.yml | 1 + src/e2e.spec.ts | 60 +++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 src/e2e.spec.ts diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index dfc6c1d..48516ad 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -35,6 +35,7 @@ jobs: - run: npm run lint - run: npm run build - run: npm run test + - run: npx testpack-cli --keep={ts-jest,typescript} src/e2e.spec.ts - name: Upload test coverage report to Codecov uses: codecov/codecov-action@v1 diff --git a/src/e2e.spec.ts b/src/e2e.spec.ts new file mode 100644 index 0000000..9d81cb1 --- /dev/null +++ b/src/e2e.spec.ts @@ -0,0 +1,60 @@ +import { count, expand, expandAll, expandN } from '.'; + +describe('count end-to-end', () => { + it('returns a count of potential strings that match pattern', () => { + const numStrings = count(/[a-z]{5}/i); + + expect(numStrings).toBe(380204032); + }); +}); + +describe('expand end-to-end', () => { + const phoneNumberPattern = /((\(555\) ?)|(555-))?\d{3}-\d{4}/; + + it('returns a count of potential strings that match pattern', () => { + const phoneNumberExpander = expand(phoneNumberPattern); + + expect(phoneNumberExpander).toHaveProperty('count', 40000000); + }); + + it('returns an iterator of strings that match pattern', () => { + const phoneNumberExpander = expand(phoneNumberPattern); + + let i = 0; + for (const phoneNumber of phoneNumberExpander.getIterator()) { + expect(phoneNumber).toMatch(phoneNumberPattern); + if (++i > 100) return; + } + }); +}); + +describe('expandAll end-to-end', () => { + it('returns all strings that match pattern', () => { + const strings = expandAll(/\d/); + + expect(strings).toHaveLength(10); + expect(strings).toEqual( + expect.arrayContaining(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']) + ); + }); +}); + +describe('expandN end-to-end', () => { + it('returns no more than N strings that match pattern', () => { + const pattern = /\d{3,5}/; + const strings = expandN(pattern, 5); + + expect(strings).toHaveLength(5); + + for (const string of strings) { + expect(string).toMatch(pattern); + } + }); + + it('returns fewer than N strings if not enough strings match pattern', () => { + const strings = expandN(/[abc]/, 100); + + expect(strings).toHaveLength(3); + expect(strings).toEqual(expect.arrayContaining(['a', 'b', 'c'])); + }); +}); From 8248e463ef3f825398e65048dcd90655366ec23f Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Sat, 6 Feb 2021 15:06:44 -0600 Subject: [PATCH 11/35] Move .babelrc into project root --- src/.babelrc => .babelrc | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/.babelrc => .babelrc (100%) diff --git a/src/.babelrc b/.babelrc similarity index 100% rename from src/.babelrc rename to .babelrc From 7bd30438be035253feff94b53c705d52d9bd90ff Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Sat, 6 Feb 2021 15:10:02 -0600 Subject: [PATCH 12/35] Move ignored file globs into Babel config --- .babelrc | 3 ++- package.json | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.babelrc b/.babelrc index 43a01f3..dcc1545 100644 --- a/.babelrc +++ b/.babelrc @@ -10,5 +10,6 @@ } ] ], - "plugins": ["@babel/plugin-proposal-class-properties"] + "plugins": ["@babel/plugin-proposal-class-properties"], + "ignore": ["**/*.spec.js", "**/*.spec.ts"] } diff --git a/package.json b/package.json index 4658c88..14526a8 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ }, "scripts": { "build": "run-s clean:* build:*", - "build:src": "babel src -d lib --extensions '.js,.ts' --ignore '**/*.spec.js','**/*.spec.ts'", + "build:src": "babel src -d lib --extensions '.js,.ts'", "build:demo": "webpack --config demo/webpack.config.js", "build:types": "tsc -p ./tsconfig.release-types.json", "clean:src": "rimraf lib/*", From b4f19028233982217b15e9c1158163091ca2820c Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Sat, 6 Feb 2021 16:37:24 -0600 Subject: [PATCH 13/35] Copy test tsconfigs to testpack directory --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 48516ad..e2349a5 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -35,7 +35,7 @@ jobs: - run: npm run lint - run: npm run build - run: npm run test - - run: npx testpack-cli --keep={ts-jest,typescript} src/e2e.spec.ts + - run: npx testpack-cli --keep={ts-jest,typescript} src/e2e.spec.ts tsconfig.release.json tsconfig.test.json - name: Upload test coverage report to Codecov uses: codecov/codecov-action@v1 From 7afaea2ed62cb785da837545c2fdf55fbd36f186 Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Sat, 6 Feb 2021 16:39:03 -0600 Subject: [PATCH 14/35] Enable verbose testpack output --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e2349a5..17150e0 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -35,7 +35,7 @@ jobs: - run: npm run lint - run: npm run build - run: npm run test - - run: npx testpack-cli --keep={ts-jest,typescript} src/e2e.spec.ts tsconfig.release.json tsconfig.test.json + - run: npx testpack-cli --verbose --keep={ts-jest,typescript} src/e2e.spec.ts tsconfig.release.json tsconfig.test.json - name: Upload test coverage report to Codecov uses: codecov/codecov-action@v1 From bc67d88250e496bd482268eac759d480560ce3f8 Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Sat, 6 Feb 2021 19:25:32 -0600 Subject: [PATCH 15/35] Add Babel config to testpack --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 17150e0..9368f4c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -35,7 +35,7 @@ jobs: - run: npm run lint - run: npm run build - run: npm run test - - run: npx testpack-cli --verbose --keep={ts-jest,typescript} src/e2e.spec.ts tsconfig.release.json tsconfig.test.json + - run: npx testpack-cli --verbose --keep={ts-jest,typescript} .babelrc tsconfig.release.json tsconfig.test.json src/e2e.spec.ts - name: Upload test coverage report to Codecov uses: codecov/codecov-action@v1 From 347296cb98c2c92323989a5be154f7a496d16d54 Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Sat, 6 Feb 2021 19:53:22 -0600 Subject: [PATCH 16/35] Revert "Move ignored file globs into Babel config" This reverts commit 7bd30438be035253feff94b53c705d52d9bd90ff. --- .babelrc | 3 +-- package.json | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.babelrc b/.babelrc index dcc1545..43a01f3 100644 --- a/.babelrc +++ b/.babelrc @@ -10,6 +10,5 @@ } ] ], - "plugins": ["@babel/plugin-proposal-class-properties"], - "ignore": ["**/*.spec.js", "**/*.spec.ts"] + "plugins": ["@babel/plugin-proposal-class-properties"] } diff --git a/package.json b/package.json index 14526a8..4658c88 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ }, "scripts": { "build": "run-s clean:* build:*", - "build:src": "babel src -d lib --extensions '.js,.ts'", + "build:src": "babel src -d lib --extensions '.js,.ts' --ignore '**/*.spec.js','**/*.spec.ts'", "build:demo": "webpack --config demo/webpack.config.js", "build:types": "tsc -p ./tsconfig.release-types.json", "clean:src": "rimraf lib/*", From 7a060df306b46526dd58376fb7212b261b028e81 Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Sat, 6 Feb 2021 20:37:17 -0600 Subject: [PATCH 17/35] Preserve Babel dependencies in testpack --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9368f4c..de80c25 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -35,7 +35,7 @@ jobs: - run: npm run lint - run: npm run build - run: npm run test - - run: npx testpack-cli --verbose --keep={ts-jest,typescript} .babelrc tsconfig.release.json tsconfig.test.json src/e2e.spec.ts + - run: npx testpack-cli --verbose --keep={@babel/*,ts-jest,typescript} .babelrc tsconfig*.json src/e2e.spec.ts - name: Upload test coverage report to Codecov uses: codecov/codecov-action@v1 From 48c4eb8d9d82709357951aa6b68fb2967013f143 Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Sat, 6 Feb 2021 20:51:13 -0600 Subject: [PATCH 18/35] Check that testpack detects broken package --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4658c88..97a4014 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "main": "lib/index.js", "types": "./lib/index.d.ts", "files": [ - "lib/" + "lib-break/" ], "sideEffects": [ "demo/**/polyfills.ts", From 6d75aa434e8ae526ff8217871aa31af4773afdfe Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Sat, 6 Feb 2021 20:57:47 -0600 Subject: [PATCH 19/35] Revert "Check that testpack detects broken package" This reverts commit 48c4eb8d9d82709357951aa6b68fb2967013f143. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 97a4014..4658c88 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "main": "lib/index.js", "types": "./lib/index.d.ts", "files": [ - "lib-break/" + "lib/" ], "sideEffects": [ "demo/**/polyfills.ts", From 6c9a77ad10525bf79b8d6b136fc56c7bd14666d0 Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Sat, 6 Feb 2021 20:58:23 -0600 Subject: [PATCH 20/35] Remove testpack verbose flag --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index de80c25..310b1d3 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -35,7 +35,7 @@ jobs: - run: npm run lint - run: npm run build - run: npm run test - - run: npx testpack-cli --verbose --keep={@babel/*,ts-jest,typescript} .babelrc tsconfig*.json src/e2e.spec.ts + - run: npx testpack-cli --keep={@babel/*,ts-jest,typescript} .babelrc tsconfig*.json src/e2e.spec.ts - name: Upload test coverage report to Codecov uses: codecov/codecov-action@v1 From af08e1c3c38b9a75808bd98533c32715aa3efea5 Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Sat, 6 Feb 2021 22:16:18 -0600 Subject: [PATCH 21/35] Test if testpack detects #9 --- .babelrc | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/.babelrc b/.babelrc index 43a01f3..5254f9b 100644 --- a/.babelrc +++ b/.babelrc @@ -1,14 +1,4 @@ { - "presets": [ - "@babel/typescript", - [ - "@babel/preset-env", - { - "targets": { - "node": "10" - } - } - ] - ], + "presets": ["@babel/typescript", "@babel/env"], "plugins": ["@babel/plugin-proposal-class-properties"] } From 7a053a6f18aaf6759b22acf743c6829e04dd346b Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Sat, 6 Feb 2021 22:33:24 -0600 Subject: [PATCH 22/35] Revert "Test if testpack detects #9" This reverts commit af08e1c3c38b9a75808bd98533c32715aa3efea5. --- .babelrc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.babelrc b/.babelrc index 5254f9b..43a01f3 100644 --- a/.babelrc +++ b/.babelrc @@ -1,4 +1,14 @@ { - "presets": ["@babel/typescript", "@babel/env"], + "presets": [ + "@babel/typescript", + [ + "@babel/preset-env", + { + "targets": { + "node": "10" + } + } + ] + ], "plugins": ["@babel/plugin-proposal-class-properties"] } From 3f402be5fb853d6401d07ab3deb46d7220d60e8e Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Sun, 7 Feb 2021 09:11:29 -0600 Subject: [PATCH 23/35] Upgrade all Webpack dependencies to latest Replace webpack-command, which only supports Webpack 4.x, with webpack-nano. --- package.json | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 4658c88..4db0367 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "scripts": { "build": "run-s clean:* build:*", "build:src": "babel src -d lib --extensions '.js,.ts' --ignore '**/*.spec.js','**/*.spec.ts'", - "build:demo": "webpack --config demo/webpack.config.js", + "build:demo": "wp --config demo/webpack.config.js", "build:types": "tsc -p ./tsconfig.release-types.json", "clean:src": "rimraf lib/*", "clean:demo": "rimraf demo/lib/*", @@ -56,7 +56,7 @@ "@typescript-eslint/eslint-plugin": "^1.13.0", "@typescript-eslint/parser": "^1.13.0", "codecov": "^3.5.0", - "css-loader": "^3.2.0", + "css-loader": "^5.0.1", "eslint": "^5.16.0", "eslint-config-airbnb-base": "^13.2.0", "eslint-config-prettier": "^6.2.0", @@ -66,19 +66,19 @@ "husky": "0.14.3", "jest": "^26.4.2", "jest-when": "^2.7.0", - "node-sass": "^4.12.0", + "node-sass": "^5.0.0", "npm-run-all": "^4.1.5", "prettier": "1.18.2", "pretty-quick": "1.7.0", "rimraf": "^2.7.1", - "sass-loader": "^7.3.1", - "style-loader": "^1.0.0", + "sass-loader": "^11.0.0", + "style-loader": "^2.0.0", "ts-jest": "^26.3.0", - "ts-loader": "^6.0.4", + "ts-loader": "^8.0.15", "typescript": "^3.6.2", - "webpack": "^4.39.3", - "webpack-command": "^0.4.2", - "worker-loader": "^2.0.0" + "webpack": "^5.21.1", + "webpack-nano": "^1.1.1", + "worker-loader": "^3.0.7" }, "dependencies": { "escape-string-regexp": "^4.0.0", From bbe2afa0f4b54f2f95d79f8796310483e4e9b48a Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Sun, 7 Feb 2021 09:17:56 -0600 Subject: [PATCH 24/35] Update Jest dependencies to latest --- jest.config.js | 2 +- package.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/jest.config.js b/jest.config.js index d736d9f..69245e8 100644 --- a/jest.config.js +++ b/jest.config.js @@ -6,7 +6,7 @@ module.exports = { ], globals: { 'ts-jest': { - tsConfig: 'tsconfig.test.json', + tsconfig: 'tsconfig.test.json', }, }, preset: 'ts-jest', diff --git a/package.json b/package.json index 4db0367..42504f2 100644 --- a/package.json +++ b/package.json @@ -62,10 +62,10 @@ "eslint-config-prettier": "^6.2.0", "eslint-import-resolver-typescript": "^1.1.1", "eslint-plugin-import": "^2.18.2", - "eslint-plugin-jest": "^22.16.0", + "eslint-plugin-jest": "^24.1.3", "husky": "0.14.3", "jest": "^26.4.2", - "jest-when": "^2.7.0", + "jest-when": "^3.2.0", "node-sass": "^5.0.0", "npm-run-all": "^4.1.5", "prettier": "1.18.2", From ee5f45567e40c3b62c8f5156c06ce2bb7f923011 Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Thu, 11 Feb 2021 20:37:07 -0600 Subject: [PATCH 25/35] Use CLI arguments to replace types tsconfig --- package.json | 2 +- tsconfig.release-types.json | 12 ------------ tsconfig.release.json | 1 + 3 files changed, 2 insertions(+), 13 deletions(-) delete mode 100644 tsconfig.release-types.json diff --git a/package.json b/package.json index 42504f2..4cba326 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "build": "run-s clean:* build:*", "build:src": "babel src -d lib --extensions '.js,.ts' --ignore '**/*.spec.js','**/*.spec.ts'", "build:demo": "wp --config demo/webpack.config.js", - "build:types": "tsc -p ./tsconfig.release-types.json", + "build:types": "tsc -p ./tsconfig.release.json --noEmit false --emitDeclarationOnly", "clean:src": "rimraf lib/*", "clean:demo": "rimraf demo/lib/*", "format": "prettier --write '{src,demo/src}/**'", diff --git a/tsconfig.release-types.json b/tsconfig.release-types.json deleted file mode 100644 index 5519f49..0000000 --- a/tsconfig.release-types.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "compilerOptions": { - // Necessary due to https://github.com/microsoft/TypeScript/issues/7546 - "allowJs": false, - "checkJs": false, - - "declaration": true, - "emitDeclarationOnly": true, - "noEmit": false - }, - "extends": "./tsconfig.release.json" -} diff --git a/tsconfig.release.json b/tsconfig.release.json index 50240f7..0ba8266 100644 --- a/tsconfig.release.json +++ b/tsconfig.release.json @@ -3,6 +3,7 @@ "allowJs": true, "baseUrl": "./", "checkJs": true, + "declaration": true, "esModuleInterop": true, "forceConsistentCasingInFileNames": true, "module": "es2015", From d9638da8099cc4095a256b495902b7e125118d12 Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Wed, 24 Feb 2021 21:37:51 -0600 Subject: [PATCH 26/35] Clean output files with the relevant build plugin Use --delete-dir-on-start with Babel. Install CleanWebpackPlugin for Webpack. --- .eslintrc.json | 2 +- demo/webpack.config.js | 4 +++- package.json | 8 +++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 607ccb0..8a7ce89 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -22,7 +22,7 @@ "import/no-extraneous-dependencies": [ "error", { - "devDependencies": ["**/*.spec.{js,ts}", "**/jest.config.js"] + "devDependencies": ["**/*.spec.{js,ts}", "**/*.config.js"] } ], "import/no-unresolved": [ diff --git a/demo/webpack.config.js b/demo/webpack.config.js index d89128b..d5a521c 100644 --- a/demo/webpack.config.js +++ b/demo/webpack.config.js @@ -1,5 +1,6 @@ -// eslint-disable-next-line @typescript-eslint/no-var-requires +/* eslint-disable @typescript-eslint/no-var-requires */ const { resolve } = require('path'); +const { CleanWebpackPlugin } = require('clean-webpack-plugin'); module.exports = { entry: './demo/src/demo.ts', @@ -9,6 +10,7 @@ module.exports = { lodash: '_', RegexColorizer: 'RegexColorizer', }, + plugins: [new CleanWebpackPlugin()], module: { rules: [ { diff --git a/package.json b/package.json index 4cba326..b88c390 100644 --- a/package.json +++ b/package.json @@ -25,12 +25,10 @@ "node": ">=10" }, "scripts": { - "build": "run-s clean:* build:*", - "build:src": "babel src -d lib --extensions '.js,.ts' --ignore '**/*.spec.js','**/*.spec.ts'", + "build": "run-s build:*", + "build:src": "babel src -d lib --extensions '.js,.ts' --ignore '**/*.spec.js','**/*.spec.ts' --delete-dir-on-start", "build:demo": "wp --config demo/webpack.config.js", "build:types": "tsc -p ./tsconfig.release.json --noEmit false --emitDeclarationOnly", - "clean:src": "rimraf lib/*", - "clean:demo": "rimraf demo/lib/*", "format": "prettier --write '{src,demo/src}/**'", "lint": "run-s lint:*", "lint:src": "tsc -p ./tsconfig.release.json && eslint . --ext .js,.ts --report-unused-disable-directives --parser-options=project:./tsconfig.release.json", @@ -55,6 +53,7 @@ "@types/lodash": "^4.14.140", "@typescript-eslint/eslint-plugin": "^1.13.0", "@typescript-eslint/parser": "^1.13.0", + "clean-webpack-plugin": "^3.0.0", "codecov": "^3.5.0", "css-loader": "^5.0.1", "eslint": "^5.16.0", @@ -70,7 +69,6 @@ "npm-run-all": "^4.1.5", "prettier": "1.18.2", "pretty-quick": "1.7.0", - "rimraf": "^2.7.1", "sass-loader": "^11.0.0", "style-loader": "^2.0.0", "ts-jest": "^26.3.0", From 061a9b66b45bbf6ff7fc09ae84fc34eef3a1a94b Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Mon, 15 Mar 2021 10:53:53 -0500 Subject: [PATCH 27/35] Upgrade to latest regexp-tree Replace local typings with the package's native typings where possible. --- package.json | 2 +- .../decimal-char-to-simple-char-transform.ts | 6 +- src/transforms/index.ts | 6 +- .../meta-to-char-class-transform.ts | 10 +- ...uantifier-to-range-quantifier-transform.ts | 6 +- src/transforms/utils.ts | 2 +- src/types/regexp-tree.d.ts | 244 +----------------- 7 files changed, 18 insertions(+), 258 deletions(-) diff --git a/package.json b/package.json index b88c390..8c8481b 100644 --- a/package.json +++ b/package.json @@ -81,7 +81,7 @@ "dependencies": { "escape-string-regexp": "^4.0.0", "pandemonium": "^1.4.1", - "regexp-tree": "^0.1.21" + "regexp-tree": "^0.1.23" }, "snyk": true } diff --git a/src/transforms/decimal-char-to-simple-char-transform.ts b/src/transforms/decimal-char-to-simple-char-transform.ts index d3a64b9..0da09d3 100644 --- a/src/transforms/decimal-char-to-simple-char-transform.ts +++ b/src/transforms/decimal-char-to-simple-char-transform.ts @@ -1,13 +1,13 @@ +import type { TransformHandlers } from 'regexp-tree'; +import type { Char } from 'regexp-tree/ast'; import escapeStringRegexp from 'escape-string-regexp'; -import { Handler } from 'regexp-tree'; -import { Char } from 'regexp-tree/ast'; /** * Interpret \#, \##, and \### escape sequences as Octal, not Decimal. * Transform them to their basic character equivalents. * Workaround for https://github.com/DmitrySoshnikov/regexp-tree/issues/74. */ -const decimalCharToSimpleCharTransform: Handler = { +const decimalCharToSimpleCharTransform: TransformHandlers = { Char(charPath) { const { node: char } = charPath; diff --git a/src/transforms/index.ts b/src/transforms/index.ts index fcd74c4..bba4424 100644 --- a/src/transforms/index.ts +++ b/src/transforms/index.ts @@ -1,9 +1,11 @@ -import { Handler } from 'regexp-tree'; +import type { transform } from 'regexp-tree'; import decimalCharToSimpleCharTransform from './decimal-char-to-simple-char-transform'; import metaToCharClassTransform from './meta-to-char-class-transform'; import simpleQuantifierToRangeQuantifierTransform from './simple-quantifier-to-range-quantifier-transform'; -const transforms: Handler[] = [ +type TransformHandlers = Parameters[1]; + +const transforms: TransformHandlers = [ decimalCharToSimpleCharTransform, metaToCharClassTransform, simpleQuantifierToRangeQuantifierTransform, diff --git a/src/transforms/meta-to-char-class-transform.ts b/src/transforms/meta-to-char-class-transform.ts index e6b425a..9c503da 100644 --- a/src/transforms/meta-to-char-class-transform.ts +++ b/src/transforms/meta-to-char-class-transform.ts @@ -1,6 +1,6 @@ -import { Handler } from 'regexp-tree'; -import { - AsExpression, +import type { TransformHandlers } from 'regexp-tree'; +import type { + AstClassMap, AstClass, AstRegExp, Char, @@ -12,7 +12,7 @@ import * as Guards from '../types/regexp-tree-guards'; import { createEscapedSimpleChar, createSimpleChar } from './utils'; type Replace = ( - parentNode: AsExpression, + parentNode: AstClassMap[ParentType], replacement: CharacterClass, child: Char ) => void; @@ -122,7 +122,7 @@ function getMetaCharExpressions( * Convert meta character classes like "\d", "\W", and "." to their ranged character * set equivalents like "[0-9]" and "[ \t\r\n~`!@#$%^&*()=+<,>.?/[{}|:;"'\]\-\\]". */ -interface MetaToCharClassTransform extends Handler { +interface MetaToCharClassTransform extends TransformHandlers { flags: string; } const metaToCharClassTransform: MetaToCharClassTransform = { diff --git a/src/transforms/simple-quantifier-to-range-quantifier-transform.ts b/src/transforms/simple-quantifier-to-range-quantifier-transform.ts index c3b1b5f..a8bbfd7 100644 --- a/src/transforms/simple-quantifier-to-range-quantifier-transform.ts +++ b/src/transforms/simple-quantifier-to-range-quantifier-transform.ts @@ -1,5 +1,5 @@ -import { Handler } from 'regexp-tree'; -import { RangeQuantifier, SimpleQuantifier } from 'regexp-tree/ast'; +import type { TransformHandlers } from 'regexp-tree'; +import type { RangeQuantifier, SimpleQuantifier } from 'regexp-tree/ast'; import * as Guards from '../types/regexp-tree-guards'; /* istanbul ignore next */ @@ -24,7 +24,7 @@ function getNumOccurrences(quantifier: SimpleQuantifier): [number, number?] { * Convert the ?, +, and * quantifiers to their equivalent ranges of * {0,1}, {1,}, and {0,} respectively */ -const simpleQuantifierToRangeQuantifierTransform: Handler = { +const simpleQuantifierToRangeQuantifierTransform: TransformHandlers = { Quantifier(quantifierPath) { const { node: quantifier } = quantifierPath; diff --git a/src/transforms/utils.ts b/src/transforms/utils.ts index fb76dca..479da38 100644 --- a/src/transforms/utils.ts +++ b/src/transforms/utils.ts @@ -1,4 +1,4 @@ -import { SimpleChar } from 'regexp-tree/ast'; +import type { SimpleChar } from 'regexp-tree/ast'; export function createSimpleChar(value: string): SimpleChar { if (value.length !== 1) throw new Error('value must be a char'); diff --git a/src/types/regexp-tree.d.ts b/src/types/regexp-tree.d.ts index fcf7975..3b339e9 100644 --- a/src/types/regexp-tree.d.ts +++ b/src/types/regexp-tree.d.ts @@ -1,247 +1,5 @@ declare module 'regexp-tree/ast' { - export type AstClass = - | 'Char' - | 'ClassRange' - | 'CharacterClass' - | 'Alternative' - | 'Disjunction' - | 'Group' - | 'Backreference' - | 'Repetition' - | 'Quantifier' - | 'Assertion' - | 'RegExp'; - - interface Base { - type: T; - loc?: { - source: string; - start: number; - end: number; - }; - } - - export interface SimpleChar extends Base<'Char'> { - value: string; - kind: 'simple'; - escaped?: true; - codePoint: number; - symbol: string; - } - - export interface SpecialChar extends Base<'Char'> { - value: string; - kind: 'meta' | 'control' | 'hex' | 'decimal' | 'oct' | 'unicode'; - codePoint: number; + export interface SimpleChar { symbol: string; } - - export type Char = SimpleChar | SpecialChar; - - export interface ClassRange extends Base<'ClassRange'> { - from: Char; - to: Char; - } - - export interface CharacterClass extends Base<'CharacterClass'> { - negative?: true; - expressions: (Char | ClassRange)[]; - } - - export interface Alternative extends Base<'Alternative'> { - expressions: Expression[]; - } - - export interface Disjunction extends Base<'Disjunction'> { - left: Expression | null; - right: Expression | null; - } - - export interface CapturingGroup extends Base<'Group'> { - capturing: true; - number: number; - name?: string; - expression: Expression | null; - } - - export interface NoncapturingGroup extends Base<'Group'> { - capturing: false; - expression: Expression | null; - } - - export type Group = CapturingGroup | NoncapturingGroup; - - export interface NumericBackreference extends Base<'Backreference'> { - kind: 'number'; - number: number; - reference: number; - } - - export interface NamedBackreference extends Base<'Backreference'> { - kind: 'name'; - number: number; - reference: string; - } - - export type Backreference = NumericBackreference | NamedBackreference; - - export interface Repetition extends Base<'Repetition'> { - expression: Expression; - quantifier: Quantifier; - } - - export interface SimpleQuantifier extends Base<'Quantifier'> { - kind: '+' | '*' | '?'; - greedy: boolean; - } - - export interface RangeQuantifier extends Base<'Quantifier'> { - kind: 'Range'; - from: number; - to?: number; - greedy: boolean; - } - - export type Quantifier = SimpleQuantifier | RangeQuantifier; - - export interface SimpleAssertion extends Base<'Assertion'> { - kind: '^' | '$' | '\\b' | '\\B'; - } - - export interface LookaroundAssertion extends Base<'Assertion'> { - kind: 'Lookahead' | 'Lookbehind'; - negative?: true; - assertion: Expression | null; - } - - export type Assertion = SimpleAssertion | LookaroundAssertion; - - export type Expression = - | Char - | CharacterClass - | Alternative - | Disjunction - | Group - | Backreference - | Repetition - | Assertion; - - export interface AstRegExp extends Base<'RegExp'> { - body: Expression | null; - flags: string; - } - - export type AsExpression = T extends 'Char' - ? Char - : T extends 'ClassRange' - ? ClassRange - : T extends 'CharacterClass' - ? CharacterClass - : T extends 'Alternative' - ? Alternative - : T extends 'Disjunction' - ? Disjunction - : T extends 'Group' - ? Group - : T extends 'Backreference' - ? Backreference - : T extends 'Repetition' - ? Repetition - : T extends 'Quantifier' - ? Quantifier - : T extends 'Assertion' - ? Assertion - : T extends 'RegExp' - ? AstRegExp - : never; - - export interface TransformResult { - getAST(): AstRegExp; - getBodyString(): string; - getFlags(): string; - toRegExp(): RegExp; - toString(): string; - } -} - -declare module 'regexp-tree' { - import { - AstClass, - AstRegExp, - AsExpression, - TransformResult, - } from 'regexp-tree/ast'; - - type Transforms = 'dotAll' | 'namedCapturingGroups' | 'xFlag'; - - export function compatTranspile( - regexp: string | RegExp | AstRegExp, - transformsWhitelist?: Transforms[] - ): TransformResult; - - interface ParserOptions { - captureLocations?: boolean; - } - - type Optimizations = - | 'charCaseInsensitiveLowerCaseTransform' - | 'charClassClassrangesMerge' - | 'charClassClassrangesToChars' - | 'charClassRemoveDuplicates' - | 'charClassToMeta' - | 'charClassToSingleChar' - | 'charCodeToSimpleChar' - | 'charEscapeUnescape' - | 'charSurrogatePairToSingleUnicode' - | 'combineRepeatingPatterns' - | 'disjunctionRemoveDuplicates' - | 'groupSingleCharsToCharClass' - | 'quantifierRangeToSymbol' - | 'quantifiersMerge' - | 'removeEmptyGroup' - | 'ungroup'; - - export function optimize( - regexp: string | RegExp | AstRegExp, - transformsWhitelist?: Optimizations[] - ): TransformResult; - - export function parse(s: string | RegExp, options?: ParserOptions): AstRegExp; - - export function generate(ast: AstRegExp): string; - - export function toRegExp(regexp: string): RegExp; - - interface NodePath { - node: AsExpression; - parent?: AsExpression; - parentPath?: NodePath; - property?: string; - index?: number; - - remove(): void; - replace( - node: AsExpression - ): NodePath | null; - update(nodeProps: Partial): void; - getPreviousSibling(): NodePath | null; - getNextSibling(): NodePath | null; - getChild(n?: number): NodePath | null; - getParent(): NodePath | null; - hasEqualSource(path: NodePath): boolean; - jsonEncode(options?: { format: string | number; useLoc: boolean }): string; - } - - type Handler = { - [nodeType in AstClass]?: (path: NodePath) => void; - } & { - init?: (ast: AstRegExp) => void; - }; - - type Handlers = Handler[] | Handler; - - export function transform( - s: string | RegExp | AstRegExp, - handlers: Handlers - ): TransformResult; } From 95d553f0472b6e9fedebb2ba511b6baa20c90107 Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Mon, 15 Mar 2021 11:02:47 -0500 Subject: [PATCH 28/35] Upgrade TypeScript / ESLint dependencies Split into separate TypeScript projects. --- .eslintrc.json | 6 ++++-- demo/src/components/demo-form.ts | 2 ++ demo/src/demo.ts | 2 +- demo/src/utils/auto-expand-field.ts | 8 ++++---- demo/src/utils/dom.ts | 5 +++-- demo/src/worker/index.ts | 2 +- demo/src/worker/messages.ts | 4 ++-- demo/src/worker/polyfills.ts | 2 +- demo/tsconfig.json | 8 ++++---- demo/webpack.config.js | 2 ++ jest.config.js | 2 +- package.json | 19 ++++++++----------- src/index.spec.ts | 2 +- src/pattern.spec.ts | 2 +- src/pattern.ts | 7 ++----- src/tsconfig.json | 8 ++++++++ src/tsconfig.test.json | 15 +++++++++++++++ tsconfig.json | 29 +++++++++++++++++++++++++++-- tsconfig.release.json | 27 --------------------------- tsconfig.test.json | 13 ------------- 20 files changed, 87 insertions(+), 78 deletions(-) create mode 100644 src/tsconfig.json create mode 100644 src/tsconfig.test.json delete mode 100644 tsconfig.release.json delete mode 100644 tsconfig.test.json diff --git a/.eslintrc.json b/.eslintrc.json index 8a7ce89..aa51691 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -9,7 +9,8 @@ "prettier/@typescript-eslint" ], "parserOptions": { - "ecmaVersion": 2018 + "ecmaVersion": 2018, + "project": ["./**/tsconfig.json", "./**/tsconfig.test.json"] }, "rules": { "import/extensions": [ @@ -49,7 +50,8 @@ "LabeledStatement", "WithStatement" ], - "@typescript-eslint/explicit-function-return-type": "off" + "@typescript-eslint/explicit-function-return-type": "off", + "@typescript-eslint/explicit-module-boundary-types": "off" }, "settings": { "import/parsers": { diff --git a/demo/src/components/demo-form.ts b/demo/src/components/demo-form.ts index 663f04b..cb6a407 100644 --- a/demo/src/components/demo-form.ts +++ b/demo/src/components/demo-form.ts @@ -27,7 +27,9 @@ export default class DemoForm { protected $errorContainer: HTMLDivElement; protected $errorMessage: HTMLPreElement; + // eslint-disable-next-line @typescript-eslint/no-empty-function public onSubmit: () => void = () => {}; + // eslint-disable-next-line @typescript-eslint/no-empty-function public onCancel: () => void = () => {}; private onInputKeydown(event: KeyboardEvent): boolean { diff --git a/demo/src/demo.ts b/demo/src/demo.ts index a13554b..b31393d 100644 --- a/demo/src/demo.ts +++ b/demo/src/demo.ts @@ -11,7 +11,7 @@ import { isCountResult, isExpandResult, } from './worker/messages'; -// @ts-ignore Ignore lack of default export. This is handled by worker-loader. +// @ts-expect-error Ignore lack of default export. This is handled by worker-loader. import DemoWorker from './worker'; import './demo.scss'; diff --git a/demo/src/utils/auto-expand-field.ts b/demo/src/utils/auto-expand-field.ts index 2690a9b..1c962db 100644 --- a/demo/src/utils/auto-expand-field.ts +++ b/demo/src/utils/auto-expand-field.ts @@ -1,18 +1,18 @@ /* eslint no-param-reassign: ["error", { "props": true, "ignorePropertyModificationsFor": ["field"] }] */ import './auto-expand-field.scss'; +type anyFn = (...args: unknown[]) => void; + /* eslint-disable @typescript-eslint/no-explicit-any */ /** * @see https://gist.github.com/fr-ser/ded7690b245223094cd876069456ed6c */ -function debounce(func: F, wait: number): F { +function debounce(func: F, wait: number): F { let timeoutID: number; return (function debounced(this: any, ...args: any[]) { clearTimeout(timeoutID); - const context = this; - - timeoutID = window.setTimeout(() => func.apply(context, args), wait); + timeoutID = window.setTimeout(() => func.apply(this, args), wait); } as any) as F; } /* eslint-enable @typescript-eslint/no-explicit-any */ diff --git a/demo/src/utils/dom.ts b/demo/src/utils/dom.ts index a2d1c74..543269c 100644 --- a/demo/src/utils/dom.ts +++ b/demo/src/utils/dom.ts @@ -1,3 +1,4 @@ -export function getElement(selector: string) { - return document.querySelector(selector) as T; +export function getElement(selector: string): T { + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + return document.querySelector(selector)!; } diff --git a/demo/src/worker/index.ts b/demo/src/worker/index.ts index ab2a9f2..aff048f 100644 --- a/demo/src/worker/index.ts +++ b/demo/src/worker/index.ts @@ -9,7 +9,7 @@ import { isExpandRequest, OptimizeResult, } from './messages'; -import { expand, toRegExp } from '../../../src/index'; +import { expand, toRegExp } from '../../../src'; function assertNeverRequest(x: never): never { throw new TypeError(`Unexpected message: ${x}`); diff --git a/demo/src/worker/messages.ts b/demo/src/worker/messages.ts index 76a27b3..48c408d 100644 --- a/demo/src/worker/messages.ts +++ b/demo/src/worker/messages.ts @@ -1,5 +1,5 @@ -/* eslint-disable no-empty-function, no-useless-constructor, @typescript-eslint/no-parameter-properties */ -import { expand } from '../../../src/index'; +/* eslint-disable max-classes-per-file, no-useless-constructor */ +import { expand } from '../../../src'; interface WorkerMessage { readonly kind: string; diff --git a/demo/src/worker/polyfills.ts b/demo/src/worker/polyfills.ts index 6858ad6..7bd8f1c 100644 --- a/demo/src/worker/polyfills.ts +++ b/demo/src/worker/polyfills.ts @@ -13,7 +13,7 @@ const featuresToPolyfill = [ 'es.symbol.iterator', ].join(','); -// @ts-ignore worker-specific function that is unrecognized +// @ts-expect-error worker-specific function that is unrecognized importScripts( `https://polyfill.app/api/polyfill?features=${featuresToPolyfill}&context=worker` ); diff --git a/demo/tsconfig.json b/demo/tsconfig.json index f939b78..7c7adc1 100644 --- a/demo/tsconfig.json +++ b/demo/tsconfig.json @@ -5,10 +5,10 @@ "es5", "es2015.core", "es2015.iterable", - "es2016.array.include", - "es2017.string" + "es2016.array.include" ] }, - "extends": "../tsconfig.release.json", - "include": ["../src", "./src"] + "extends": "../tsconfig.json", + "include": ["src"], + "references": [{ "path": "../src" }] } diff --git a/demo/webpack.config.js b/demo/webpack.config.js index d5a521c..028909c 100644 --- a/demo/webpack.config.js +++ b/demo/webpack.config.js @@ -1,3 +1,4 @@ +/// ; /* eslint-disable @typescript-eslint/no-var-requires */ const { resolve } = require('path'); const { CleanWebpackPlugin } = require('clean-webpack-plugin'); @@ -31,6 +32,7 @@ module.exports = { options: { compilerOptions: { noEmit: false }, configFile: resolve(__dirname, './tsconfig.json'), + projectReferences: true, }, }, ], diff --git a/jest.config.js b/jest.config.js index 69245e8..e926263 100644 --- a/jest.config.js +++ b/jest.config.js @@ -6,7 +6,7 @@ module.exports = { ], globals: { 'ts-jest': { - tsconfig: 'tsconfig.test.json', + tsconfig: 'src/tsconfig.test.json', }, }, preset: 'ts-jest', diff --git a/package.json b/package.json index 8c8481b..4213596 100644 --- a/package.json +++ b/package.json @@ -28,12 +28,9 @@ "build": "run-s build:*", "build:src": "babel src -d lib --extensions '.js,.ts' --ignore '**/*.spec.js','**/*.spec.ts' --delete-dir-on-start", "build:demo": "wp --config demo/webpack.config.js", - "build:types": "tsc -p ./tsconfig.release.json --noEmit false --emitDeclarationOnly", + "build:types": "tsc --noEmit false --emitDeclarationOnly", "format": "prettier --write '{src,demo/src}/**'", - "lint": "run-s lint:*", - "lint:src": "tsc -p ./tsconfig.release.json && eslint . --ext .js,.ts --report-unused-disable-directives --parser-options=project:./tsconfig.release.json", - "lint:demo": "tsc -p ./demo/tsconfig.json && eslint . --ext .js,.ts --report-unused-disable-directives --parser-options=project:./demo/tsconfig.json", - "lint:tests": "tsc -p ./tsconfig.test.json && eslint . --ext .js,.ts --report-unused-disable-directives --parser-options=project:./tsconfig.test.json", + "lint": "tsc -b && eslint . --report-unused-disable-directives", "precommit": "pretty-quick --staged", "prepublish": "npx publish-please guard", "publish-please": "npx publish-please", @@ -51,15 +48,15 @@ "@types/jest": "^26.0.10", "@types/jest-when": "^2.4.1", "@types/lodash": "^4.14.140", - "@typescript-eslint/eslint-plugin": "^1.13.0", - "@typescript-eslint/parser": "^1.13.0", + "@typescript-eslint/eslint-plugin": "^4.17.0", + "@typescript-eslint/parser": "^4.17.0", "clean-webpack-plugin": "^3.0.0", "codecov": "^3.5.0", "css-loader": "^5.0.1", - "eslint": "^5.16.0", - "eslint-config-airbnb-base": "^13.2.0", + "eslint": "^7.22.0", + "eslint-config-airbnb-base": "^14.2.1", "eslint-config-prettier": "^6.2.0", - "eslint-import-resolver-typescript": "^1.1.1", + "eslint-import-resolver-typescript": "^2.4.0", "eslint-plugin-import": "^2.18.2", "eslint-plugin-jest": "^24.1.3", "husky": "0.14.3", @@ -73,7 +70,7 @@ "style-loader": "^2.0.0", "ts-jest": "^26.3.0", "ts-loader": "^8.0.15", - "typescript": "^3.6.2", + "typescript": "^4.2.3", "webpack": "^5.21.1", "webpack-nano": "^1.1.1", "worker-loader": "^3.0.7" diff --git a/src/index.spec.ts b/src/index.spec.ts index dc0e73b..97ff4d7 100644 --- a/src/index.spec.ts +++ b/src/index.spec.ts @@ -1,4 +1,4 @@ -import * as indexLib from './index'; +import * as indexLib from '.'; import * as patternLib from './pattern'; describe('index', () => { diff --git a/src/pattern.spec.ts b/src/pattern.spec.ts index 4c7ecd3..869d2a9 100644 --- a/src/pattern.spec.ts +++ b/src/pattern.spec.ts @@ -7,7 +7,7 @@ import * as randomSort from './sorts/fisher-yates-random'; import * as chooseRandom from './sorts/number-random'; import * as chooseRandomWeighted from './sorts/weighted-random'; -function measureAverageTime(fn: Function, numTrials: number) { +function measureAverageTime(fn: () => void, numTrials: number) { let totalTime = 0; for (let i = 0; i < numTrials; i++) { diff --git a/src/pattern.ts b/src/pattern.ts index 1a8fa79..ee77a17 100644 --- a/src/pattern.ts +++ b/src/pattern.ts @@ -2,11 +2,8 @@ import { compatTranspile, parse, transform } from 'regexp-tree'; import Expander from './Expander'; import Expansion from './Expansion'; // Circular reference for spying/mocking in tests -import { - expand as mockableExpand, - toRegExp as mockableToRegExp, -} from './index'; -import transforms from './transforms/index'; +import { expand as mockableExpand, toRegExp as mockableToRegExp } from '.'; +import transforms from './transforms'; // From https://triin.net/2011/10/19/Meta_Regular_Expression const regexAsStringPattern = /^\/([^/\[\\]|\\.|\[([^\]\\]|\\.)*\])*\/[a-z]*$/i; diff --git a/src/tsconfig.json b/src/tsconfig.json new file mode 100644 index 0000000..2c6c771 --- /dev/null +++ b/src/tsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "lib": ["es5", "es2015.core", "es2015.iterable", "es2016.array.include"] + }, + "extends": "../tsconfig.json", + "exclude": ["../**/*.spec.ts", "../**/*.config.js"], + "include": ["./**/*"] +} diff --git a/src/tsconfig.test.json b/src/tsconfig.test.json new file mode 100644 index 0000000..c4ac774 --- /dev/null +++ b/src/tsconfig.test.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "lib": [ + "es5", + "es2015.core", + "es2015.iterable", + "es2016.array.include", + "es2017.string" + ], + "types": ["jest", "regexp-tree", "./types/regexp-tree"] + }, + "extends": "../tsconfig.json", + "include": ["./**/*.spec.ts", "../**/*.config.js"], + "references": [{ "path": "./" }] +} diff --git a/tsconfig.json b/tsconfig.json index ad750d9..b9436d5 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,4 +1,29 @@ -// These settings are only directed at IDEs that auto-detect the tsconfig file. { - "extends": "./tsconfig.test.json" + "compilerOptions": { + "allowJs": true, + "baseUrl": ".", + "checkJs": true, + "composite": true, + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "module": "es2015", + "downlevelIteration": true, + "moduleResolution": "node", + "noImplicitReturns": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "outDir": "../lib", + "pretty": true, + "rootDir": ".", + "skipLibCheck": true, + "sourceMap": true, + "strict": true, + "types": [] + }, + "files": [], + "references": [ + { "path": "./demo" }, + { "path": "./src" }, + { "path": "./src/tsconfig.test.json" } + ] } diff --git a/tsconfig.release.json b/tsconfig.release.json deleted file mode 100644 index 0ba8266..0000000 --- a/tsconfig.release.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "compilerOptions": { - "allowJs": true, - "baseUrl": "./", - "checkJs": true, - "declaration": true, - "esModuleInterop": true, - "forceConsistentCasingInFileNames": true, - "module": "es2015", - "lib": ["es5", "es2015.core", "es2015.iterable", "es2016.array.include"], - "downlevelIteration": true, - "moduleResolution": "node", - "noEmit": true, - "noImplicitReturns": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "outDir": "./lib", - "paths": { - "regexp-tree": ["src/types/regexp-tree.d.ts"] - }, - "pretty": true, - "sourceMap": true, - "strict": true - }, - "exclude": ["**/*.spec.ts", "**/*.config.js"], - "include": ["src"] -} diff --git a/tsconfig.test.json b/tsconfig.test.json deleted file mode 100644 index df69e81..0000000 --- a/tsconfig.test.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "compilerOptions": { - "lib": [ - "es5", - "es2015.core", - "es2015.iterable", - "es2016.array.include", - "es2017.string" - ] - }, - "exclude": [""], - "extends": "./tsconfig.release.json" -} From 4fd17ff2f7fb1249c7a6260bfc98d7ea9f490939 Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Mon, 15 Mar 2021 17:45:38 -0500 Subject: [PATCH 29/35] Upgrade Pandemonium to latest Use native typings. --- package.json | 2 +- src/types/pandemonium.d.ts | 13 ------------- 2 files changed, 1 insertion(+), 14 deletions(-) delete mode 100644 src/types/pandemonium.d.ts diff --git a/package.json b/package.json index 4213596..a41a967 100644 --- a/package.json +++ b/package.json @@ -77,7 +77,7 @@ }, "dependencies": { "escape-string-regexp": "^4.0.0", - "pandemonium": "^1.4.1", + "pandemonium": "^2.0.0", "regexp-tree": "^0.1.23" }, "snyk": true diff --git a/src/types/pandemonium.d.ts b/src/types/pandemonium.d.ts deleted file mode 100644 index a7946a2..0000000 --- a/src/types/pandemonium.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -declare module 'pandemonium/shuffle' { - type Shuffle = (items: T[]) => T[]; - - const shuffle: Shuffle; - export default shuffle; -} - -declare module 'pandemonium/weighted-random-index' { - type WeightedRandomIndex = (weights: number[]) => number; - - const weightedRandomIndex: WeightedRandomIndex; - export default weightedRandomIndex; -} From ff96f3a04dd1abfb2ad64576e12cc4010f20ff03 Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Mon, 15 Mar 2021 18:32:51 -0500 Subject: [PATCH 30/35] Upgrade Prettier to latest version Reformat all files to match ruleset. --- .eslintrc.json | 3 +- demo/src/components/demo-output.ts | 4 +-- demo/src/demo.ts | 2 +- demo/src/utils/url-storage.ts | 2 +- package.json | 8 ++--- src/expanders/character-class-pattern.ts | 8 ++--- src/expanders/disjunction-pattern.ts | 2 +- src/expanders/repetition-pattern.ts | 2 +- src/helpers/iterate-sorted.ts | 4 +-- src/pattern.spec.ts | 30 +++++++++---------- .../meta-to-char-class-transform.ts | 4 +-- 11 files changed, 34 insertions(+), 35 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index aa51691..9167687 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -5,8 +5,7 @@ "plugin:jest/recommended", "plugin:@typescript-eslint/eslint-recommended", "plugin:@typescript-eslint/recommended", - "prettier", - "prettier/@typescript-eslint" + "prettier" ], "parserOptions": { "ecmaVersion": 2018, diff --git a/demo/src/components/demo-output.ts b/demo/src/components/demo-output.ts index c019c6e..dc41164 100644 --- a/demo/src/components/demo-output.ts +++ b/demo/src/components/demo-output.ts @@ -32,11 +32,11 @@ export default class DemoOutput { if (isBlockOutput) { this.$expansions.innerHTML = expansions - .map(string => `
${escape(string)}
`) + .map((value) => `
${escape(value)}
`) .join('\n'); } else { this.$expansions.innerHTML = expansions - .map(string => `${escape(string)}`) + .map((value) => `${escape(value)}`) .join(delimiter); } diff --git a/demo/src/demo.ts b/demo/src/demo.ts index b31393d..0985c95 100644 --- a/demo/src/demo.ts +++ b/demo/src/demo.ts @@ -97,7 +97,7 @@ $form.onCancel = () => { hideWaitingState(); }; -UrlStorage.onChange(newData => { +UrlStorage.onChange((newData) => { $form.populate(newData); if (!$form.validate()) return; diff --git a/demo/src/utils/url-storage.ts b/demo/src/utils/url-storage.ts index 6d84fcd..95b21ba 100644 --- a/demo/src/utils/url-storage.ts +++ b/demo/src/utils/url-storage.ts @@ -56,7 +56,7 @@ export function write(data: FormInput) { * @param fn The function to run and receive the new data */ export function onChange(fn: (newData: StoredInput) => void) { - return history.listen(location => { + return history.listen((location) => { const newData = parse(location); fn(newData); }); diff --git a/package.json b/package.json index a41a967..5e6b4fc 100644 --- a/package.json +++ b/package.json @@ -55,17 +55,17 @@ "css-loader": "^5.0.1", "eslint": "^7.22.0", "eslint-config-airbnb-base": "^14.2.1", - "eslint-config-prettier": "^6.2.0", + "eslint-config-prettier": "^8.1.0", "eslint-import-resolver-typescript": "^2.4.0", "eslint-plugin-import": "^2.18.2", "eslint-plugin-jest": "^24.1.3", - "husky": "0.14.3", + "husky": "5.1.3", "jest": "^26.4.2", "jest-when": "^3.2.0", "node-sass": "^5.0.0", "npm-run-all": "^4.1.5", - "prettier": "1.18.2", - "pretty-quick": "1.7.0", + "prettier": "2.2.1", + "pretty-quick": "3.1.0", "sass-loader": "^11.0.0", "style-loader": "^2.0.0", "ts-jest": "^26.3.0", diff --git a/src/expanders/character-class-pattern.ts b/src/expanders/character-class-pattern.ts index 0502770..db03df6 100644 --- a/src/expanders/character-class-pattern.ts +++ b/src/expanders/character-class-pattern.ts @@ -19,7 +19,7 @@ function getReferencedCodePoints( return [expression.codePoint]; } -const allCodePointOptions = Chars.all.map(char => char.charCodeAt(0)); +const allCodePointOptions = Chars.all.map((char) => char.charCodeAt(0)); /** * Expand an expression which represents a single character from a @@ -47,10 +47,10 @@ export function expandCharacterClass(this: Expander, node: CharacterClass) { const expandedClass = allCodePointOptions // For a whitelist set, discard code points not referenced in the set - .filter(option => !node.negative || !referencedCodePoints.includes(option)) + .filter((opt) => !node.negative || !referencedCodePoints.includes(opt)) // For a blacklist set, discard code points referenced in the set - .filter(option => node.negative || referencedCodePoints.includes(option)) - .map(codePoint => String.fromCodePoint(codePoint)) + .filter((opt) => node.negative || referencedCodePoints.includes(opt)) + .map((codePoint) => String.fromCodePoint(codePoint)) .reduce(applyCaseInsensitiveFlag, []); const sortChars = () => sortRandom(expandedClass); diff --git a/src/expanders/disjunction-pattern.ts b/src/expanders/disjunction-pattern.ts index 116e08c..c8a32a8 100644 --- a/src/expanders/disjunction-pattern.ts +++ b/src/expanders/disjunction-pattern.ts @@ -13,7 +13,7 @@ import { iterateWeightedByCount } from '../helpers/iterate-sorted'; */ export function expandDisjunction(this: Expander, node: Disjunction) { const expressions = [node.left, node.right]; - const expansions = expressions.map(e => this.expandExpression(e)); + const expansions = expressions.map((e) => this.expandExpression(e)); const expandBothSides = () => iterateWeightedByCount(expansions); const iterationsSum = expansions[0].count + expansions[1].count; diff --git a/src/expanders/repetition-pattern.ts b/src/expanders/repetition-pattern.ts index d266d88..a86f3ac 100644 --- a/src/expanders/repetition-pattern.ts +++ b/src/expanders/repetition-pattern.ts @@ -42,7 +42,7 @@ export function expandRepetition(this: Expander, node: Repetition): Expansion { // Calculate the expansions for each quantity of repetition, like "a{1}", // "a{2}", "a{3}", etc. - const allExpansions = numOccurrenceOptions.map(numOccurrences => { + const allExpansions = numOccurrenceOptions.map((numOccurrences) => { if (numOccurrences <= 0) { return Expansion.Blank; } diff --git a/src/helpers/iterate-sorted.ts b/src/helpers/iterate-sorted.ts index 8897961..661e23f 100644 --- a/src/helpers/iterate-sorted.ts +++ b/src/helpers/iterate-sorted.ts @@ -11,8 +11,8 @@ import chooseRandomWeighted from '../sorts/weighted-random'; export function* iterateWeightedByCount( options: Expansion[] ): IterableIterator { - const iterators = options.map(option => option.getIterator()); - const weights = options.map(option => option.count); + const iterators = options.map((option) => option.getIterator()); + const weights = options.map((option) => option.count); while (iterators.length > 0) { // Randomly choose an option, weighted by the size of the expansion. diff --git a/src/pattern.spec.ts b/src/pattern.spec.ts index 869d2a9..9172c74 100644 --- a/src/pattern.spec.ts +++ b/src/pattern.spec.ts @@ -100,7 +100,7 @@ describe('expand', () => { // Keep a stable order for consistent tests. sortFn = jest .spyOn(randomSort, 'default') - .mockImplementation(items => [...items]); + .mockImplementation((items) => [...items]); randomWeightedFn = jest .spyOn(chooseRandomWeighted, 'default') @@ -108,7 +108,7 @@ describe('expand', () => { randomFn = jest .spyOn(chooseRandom, 'default') - .mockImplementation(minValue => minValue); + .mockImplementation((minValue) => minValue); }); it('normalizes pattern with toRegExp()', () => { @@ -610,18 +610,18 @@ describe('expand', () => { it.each([/(.|\r)/s, /[\s\S]/, /[\w\W]/, /[\d\D]/])( 'includes all supported characters in %p', - regex => { + (regex) => { const result = expandAll(regex); expect(result).toHaveLength(Chars.all.length); - Chars.all.forEach(char => { + Chars.all.forEach((char) => { expect(result).toContain(char); }); } ); it('expands repeated character class', () => { - const allTwoDigitNumbers = fill(0, 99).map(num => + const allTwoDigitNumbers = fill(0, 99).map((num) => num.toString().padStart(2, '0') ); @@ -787,7 +787,7 @@ describe('expand', () => { // Re-enable the normal sorting behavior beforeEach(() => { - [sortFn, randomWeightedFn, randomFn].forEach(mockFn => + [sortFn, randomWeightedFn, randomFn].forEach((mockFn) => mockFn.mockRestore() ); }); @@ -825,7 +825,7 @@ describe('expand', () => { const results = expandN(/[ab]{1,2}/, 2); resultsAllTrials = resultsAllTrials.concat(results); } - const resultsByLength = resultsAllTrials.map(result => result.length); + const resultsByLength = resultsAllTrials.map((result) => result.length); const uniqueLengths = resultsByLength.filter(isUnique); expect(uniqueLengths.length).toBeGreaterThan(1); @@ -842,7 +842,7 @@ describe('expand', () => { (iChar: number) => { const results = expandN(input, 50); - const resultsThisChar = results.map(result => + const resultsThisChar = results.map((result) => result.charAt(iChar - 1) ); const uniqueThisChar = resultsThisChar.filter(isUnique); @@ -1083,7 +1083,7 @@ describe('expand', () => { 'e', // POSIX ERE 'q', // Literal 'X', // Extra syntax - ].forEach(modeModifier => { + ].forEach((modeModifier) => { it.each([ ['positive at start', `(?${modeModifier})test`], ['positive in middle', `te(?${modeModifier})st`], @@ -1175,7 +1175,7 @@ describe('expand', () => { 'u', // upper 'h', // blank 'V', // vertical whitespace - ].forEach(posixClass => { + ].forEach((posixClass) => { it.each([ ['POSIX class', `[[:${posixClass}:]]`], ['negative POSIX class', `[[:^${posixClass}:]]`], @@ -1204,7 +1204,7 @@ describe('expand', () => { 'Upper', 'Word', 'XDigit', - ].forEach(javaPosixClass => { + ].forEach((javaPosixClass) => { it.each([ ['Java POSIX class', `\p{${javaPosixClass}}`], ['Java POSIX class', `\p{Is${javaPosixClass}}`], @@ -1265,7 +1265,7 @@ describe('expand', () => { 'Thai', 'Tibetan', 'Yi', - ].forEach(unicodeScript => { + ].forEach((unicodeScript) => { it.each([`\p{${unicodeScript}}`, `\p{Is${unicodeScript}}`])( 'does not recognize RegEx syntax: Unicode script /%s/', (input: string) => { @@ -1383,7 +1383,7 @@ describe('expand', () => { 'Arabic_Presentation_Forms-B', 'Halfwidth_and_Fullwidth_Forms', 'Specials', - ].forEach(unicodeBlock => { + ].forEach((unicodeBlock) => { function testUnicodeBlock(_: string, input: string) { const result = expandAll(input); expect(result).toHaveLength(1); @@ -1501,7 +1501,7 @@ describe('expand', () => { 'Cs', 'Unassigned', 'Cn', - ].forEach(unicodeCategory => { + ].forEach((unicodeCategory) => { it.each([ ['Longhand format', `\p{${unicodeCategory}}`], ['Longhand format', `\p{Is${unicodeCategory}}`], @@ -1529,7 +1529,7 @@ describe('expand', () => { }); // From https://www.regular-expressions.info/unicode.html#category - ['L', 'M', 'Z', 'S', 'N', 'P', 'C'].forEach(unicodeCategory => { + ['L', 'M', 'Z', 'S', 'N', 'P', 'C'].forEach((unicodeCategory) => { it.each([['Shorthand format', `\p${unicodeCategory}`]])( 'does not recognize RegEx syntax: Unicode category %s /%s/', (_: string, input: string) => { diff --git a/src/transforms/meta-to-char-class-transform.ts b/src/transforms/meta-to-char-class-transform.ts index 9c503da..0105ad8 100644 --- a/src/transforms/meta-to-char-class-transform.ts +++ b/src/transforms/meta-to-char-class-transform.ts @@ -61,7 +61,7 @@ const optionsDigit = Chars.digits.map(createSimpleChar); const optionsWhitespace = Chars.whitespace.map(createSimpleChar); const needEscape = [']', '-', '\\']; -const noEscape = Chars.basicSpecial.filter(c => !needEscape.includes(c)); +const noEscape = Chars.basicSpecial.filter((c) => !needEscape.includes(c)); const optionsOther = [ ...noEscape.map(createSimpleChar), ...needEscape.map(createEscapedSimpleChar), @@ -78,7 +78,7 @@ function getMetaCharExpressions( const optionsNewLine = createSimpleChar('\n'); const optionsDotAll = regExpFlags.includes('s') ? [optionsNewLine] : []; const whitespaceNoBreaks = Chars.whitespace.filter( - c => !'\r\n'.includes(c) + (c) => !'\r\n'.includes(c) ); const optionsWhitespaceNoBreak = whitespaceNoBreaks.map(createSimpleChar); From ba61cf498e10c7e3d9717587d0201e35927f8378 Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Mon, 15 Mar 2021 18:49:24 -0500 Subject: [PATCH 31/35] Upgrade Jest dependencies to latest --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 5e6b4fc..af078f6 100644 --- a/package.json +++ b/package.json @@ -58,17 +58,17 @@ "eslint-config-prettier": "^8.1.0", "eslint-import-resolver-typescript": "^2.4.0", "eslint-plugin-import": "^2.18.2", - "eslint-plugin-jest": "^24.1.3", + "eslint-plugin-jest": "^24.3.1", "husky": "5.1.3", "jest": "^26.4.2", - "jest-when": "^3.2.0", + "jest-when": "^3.2.1", "node-sass": "^5.0.0", "npm-run-all": "^4.1.5", "prettier": "2.2.1", "pretty-quick": "3.1.0", "sass-loader": "^11.0.0", "style-loader": "^2.0.0", - "ts-jest": "^26.3.0", + "ts-jest": "^26.5.3", "ts-loader": "^8.0.15", "typescript": "^4.2.3", "webpack": "^5.21.1", From a5af7b7b6861334e6c3647cb610edfcf2f3ec302 Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Mon, 15 Mar 2021 19:01:49 -0500 Subject: [PATCH 32/35] Upgrade Webpack dependencies to latest --- package.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index af078f6..8b04e68 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "@typescript-eslint/parser": "^4.17.0", "clean-webpack-plugin": "^3.0.0", "codecov": "^3.5.0", - "css-loader": "^5.0.1", + "css-loader": "^5.1.3", "eslint": "^7.22.0", "eslint-config-airbnb-base": "^14.2.1", "eslint-config-prettier": "^8.1.0", @@ -66,14 +66,14 @@ "npm-run-all": "^4.1.5", "prettier": "2.2.1", "pretty-quick": "3.1.0", - "sass-loader": "^11.0.0", + "sass-loader": "^11.0.1", "style-loader": "^2.0.0", "ts-jest": "^26.5.3", - "ts-loader": "^8.0.15", + "ts-loader": "^8.0.18", "typescript": "^4.2.3", - "webpack": "^5.21.1", + "webpack": "^5.26.0", "webpack-nano": "^1.1.1", - "worker-loader": "^3.0.7" + "worker-loader": "^3.0.8" }, "dependencies": { "escape-string-regexp": "^4.0.0", From fb14629167abb494d5359a70eeb1ba53adb0f093 Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Mon, 15 Mar 2021 19:27:15 -0500 Subject: [PATCH 33/35] Update Babel dependencies to latest version --- package.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 8b04e68..bb5ebd5 100644 --- a/package.json +++ b/package.json @@ -38,11 +38,11 @@ "test": "jest --coverage" }, "devDependencies": { - "@babel/cli": "^7.5.5", - "@babel/core": "^7.5.5", - "@babel/plugin-proposal-class-properties": "^7.5.5", - "@babel/preset-env": "^7.5.5", - "@babel/preset-typescript": "^7.3.3", + "@babel/cli": "^7.13.10", + "@babel/core": "^7.13.10", + "@babel/plugin-proposal-class-properties": "^7.13.0", + "@babel/preset-env": "^7.13.10", + "@babel/preset-typescript": "^7.13.0", "@types/escape-string-regexp": "^2.0.1", "@types/history": "^4.7.3", "@types/jest": "^26.0.10", From 0863a2a11c65809f04477e9c7586270b1c1780a7 Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Mon, 15 Mar 2021 19:28:00 -0500 Subject: [PATCH 34/35] Upgrade TypeScript / ESLint dependencies to latest --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index bb5ebd5..875ba89 100644 --- a/package.json +++ b/package.json @@ -48,8 +48,8 @@ "@types/jest": "^26.0.10", "@types/jest-when": "^2.4.1", "@types/lodash": "^4.14.140", - "@typescript-eslint/eslint-plugin": "^4.17.0", - "@typescript-eslint/parser": "^4.17.0", + "@typescript-eslint/eslint-plugin": "^4.18.0", + "@typescript-eslint/parser": "^4.18.0", "clean-webpack-plugin": "^3.0.0", "codecov": "^3.5.0", "css-loader": "^5.1.3", From 97ddc5412c83293e8eb9e1a808ca4ae6b05c76fc Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Mon, 15 Mar 2021 20:30:11 -0500 Subject: [PATCH 35/35] Bump patch version to 2.0.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 875ba89..d959c20 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "regex-to-strings", - "version": "2.0.1", + "version": "2.0.2", "repository": { "type": "git", "url": "git+https://github.com/wimpyprogrammer/regex-to-strings.git"