Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
"plugin:jest/recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
"prettier/@typescript-eslint"
"prettier"
],
"parserOptions": {
"ecmaVersion": 2018
"ecmaVersion": 2018,
"project": ["./**/tsconfig.json", "./**/tsconfig.test.json"]
},
"rules": {
"import/extensions": [
Expand All @@ -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": [
Expand All @@ -49,7 +49,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": {
Expand Down
2 changes: 2 additions & 0 deletions demo/src/components/demo-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions demo/src/components/demo-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ export default class DemoOutput {

if (isBlockOutput) {
this.$expansions.innerHTML = expansions
.map(string => `<div class="alert alert-light">${escape(string)}</div>`)
.map((value) => `<div class="alert alert-light">${escape(value)}</div>`)
.join('\n');
} else {
this.$expansions.innerHTML = expansions
.map(string => `<span>${escape(string)}</span>`)
.map((value) => `<span>${escape(value)}</span>`)
.join(delimiter);
}

Expand Down
4 changes: 2 additions & 2 deletions demo/src/demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -97,7 +97,7 @@ $form.onCancel = () => {
hideWaitingState();
};

UrlStorage.onChange(newData => {
UrlStorage.onChange((newData) => {
$form.populate(newData);
if (!$form.validate()) return;

Expand Down
8 changes: 4 additions & 4 deletions demo/src/utils/auto-expand-field.ts
Original file line number Diff line number Diff line change
@@ -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<F extends Function>(func: F, wait: number): F {
function debounce<F extends anyFn>(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 */
Expand Down
5 changes: 3 additions & 2 deletions demo/src/utils/dom.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export function getElement<T extends Element>(selector: string) {
return document.querySelector(selector) as T;
export function getElement<T extends Element>(selector: string): T {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return document.querySelector(selector)!;
}
2 changes: 1 addition & 1 deletion demo/src/utils/url-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
2 changes: 1 addition & 1 deletion demo/src/worker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down
4 changes: 2 additions & 2 deletions demo/src/worker/messages.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion demo/src/worker/polyfills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
);
8 changes: 4 additions & 4 deletions demo/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" }]
}
6 changes: 5 additions & 1 deletion demo/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
/// <reference types="node" />;
/* eslint-disable @typescript-eslint/no-var-requires */
const { resolve } = require('path');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');

module.exports = {
entry: './demo/src/demo.ts',
Expand All @@ -9,6 +11,7 @@ module.exports = {
lodash: '_',
RegexColorizer: 'RegexColorizer',
},
plugins: [new CleanWebpackPlugin()],
module: {
rules: [
{
Expand All @@ -29,6 +32,7 @@ module.exports = {
options: {
compilerOptions: { noEmit: false },
configFile: resolve(__dirname, './tsconfig.json'),
projectReferences: true,
},
},
],
Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
],
globals: {
'ts-jest': {
tsConfig: 'tsconfig.test.json',
tsconfig: 'src/tsconfig.test.json',
},
},
preset: 'ts-jest',
Expand Down
73 changes: 34 additions & 39 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,65 +25,60 @@
"node": ">=10"
},
"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:types": "tsc -p ./tsconfig.release-types.json",
"clean:src": "rimraf lib/*",
"clean:demo": "rimraf demo/lib/*",
"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 --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",
"publish-please-prereqs": "npm run lint && npm run test && npm run build",
"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",
"@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.18.0",
"@typescript-eslint/parser": "^4.18.0",
"clean-webpack-plugin": "^3.0.0",
"codecov": "^3.5.0",
"css-loader": "^3.2.0",
"eslint": "^5.16.0",
"eslint-config-airbnb-base": "^13.2.0",
"eslint-config-prettier": "^6.2.0",
"eslint-import-resolver-typescript": "^1.1.1",
"css-loader": "^5.1.3",
"eslint": "^7.22.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-config-prettier": "^8.1.0",
"eslint-import-resolver-typescript": "^2.4.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-jest": "^22.16.0",
"husky": "0.14.3",
"eslint-plugin-jest": "^24.3.1",
"husky": "5.1.3",
"jest": "^26.4.2",
"jest-when": "^2.7.0",
"node-sass": "^4.12.0",
"jest-when": "^3.2.1",
"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",
"ts-jest": "^26.3.0",
"ts-loader": "^6.0.4",
"typescript": "^3.6.2",
"webpack": "^4.39.3",
"webpack-command": "^0.4.2",
"worker-loader": "^2.0.0"
"prettier": "2.2.1",
"pretty-quick": "3.1.0",
"sass-loader": "^11.0.1",
"style-loader": "^2.0.0",
"ts-jest": "^26.5.3",
"ts-loader": "^8.0.18",
"typescript": "^4.2.3",
"webpack": "^5.26.0",
"webpack-nano": "^1.1.1",
"worker-loader": "^3.0.8"
},
"dependencies": {
"escape-string-regexp": "^4.0.0",
"pandemonium": "^1.4.1",
"regexp-tree": "^0.1.21"
"pandemonium": "^2.0.0",
"regexp-tree": "^0.1.23"
},
"snyk": true
}
8 changes: 4 additions & 4 deletions src/expanders/character-class-pattern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/expanders/disjunction-pattern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/expanders/repetition-pattern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/iterate-sorted.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import chooseRandomWeighted from '../sorts/weighted-random';
export function* iterateWeightedByCount(
options: Expansion[]
): IterableIterator<string> {
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.
Expand Down
2 changes: 1 addition & 1 deletion src/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as indexLib from './index';
import * as indexLib from '.';
import * as patternLib from './pattern';

describe('index', () => {
Expand Down
Loading