Skip to content

Commit

Permalink
chore: apply ESLint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Jan 3, 2025
1 parent e3df47d commit 4200642
Show file tree
Hide file tree
Showing 36 changed files with 1,213 additions and 814 deletions.
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

14 changes: 0 additions & 14 deletions .eslintrc

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/feature.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
jobs:
test:
runs-on: ubuntu-latest
environment: release
name: Test
runs-on: ubuntu-latest
steps:
- name: setup repository
uses: actions/checkout@v3
Expand All @@ -11,7 +11,7 @@ jobs:
- name: setup node.js
uses: actions/setup-node@v3
with:
node-version: "18"
node-version: '18'
- run: npm ci
- run: npm run lint
- run: npm run test
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
jobs:
test:
runs-on: ubuntu-latest
environment: release
name: Test
runs-on: ubuntu-latest
steps:
- name: setup repository
uses: actions/checkout@v3
Expand All @@ -11,15 +11,15 @@ jobs:
- name: setup node.js
uses: actions/setup-node@v3
with:
node-version: "18"
node-version: '18'
- run: npm ci
- run: npm run lint
- run: npm run test
- run: npm run build
- run: npx semantic-release
env:
- env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npx semantic-release
name: Test, build and release
on:
push:
Expand Down
37 changes: 37 additions & 0 deletions eslint.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const auto = require('eslint-config-canonical/configurations/auto');
const ava = require('eslint-config-canonical/configurations/ava');
const node = require('eslint-config-canonical/configurations/node');

module.exports = [
...auto,
ava.recommended,
{
files: ['**/*.cjs'],
...node.recommended,
},
{
rules: {
'@typescript-eslint/no-explicit-any': 0,
'func-style': 0,
'id-length': 0,
'no-template-curly-in-string': 0,
'regexp/no-unused-capturing-group': 0,
'regexp/optimal-quantifier-concatenation': 0,
'require-unicode-regexp': 0,
},
},
{
ignores: [
'package-lock.json',
'dist',
'node_modules',
'src/pg-formatter',
'*.log',
'.*',
'!.github',
'!.gitignore',
'!.husky',
'!.releaserc',
],
},
];
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"benny": "^3.7.1",
"coveralls": "^3.1.1",
"del-cli": "^4.0.1",
"eslint": "^7.32.0",
"eslint-config-canonical": "^28.0.0",
"eslint": "^9.17.0",
"eslint-config-canonical": "^44.3.36",
"faker": "^5.5.3",
"husky": "^7.0.4",
"npm-watch": "^0.11.0",
Expand All @@ -55,18 +55,18 @@
"type": "git",
"url": "[email protected]:gajus/liqe.git"
},
"watch": {
"compile-parser": "src/grammar.ne"
},
"scripts": {
"watch": "npm-watch",
"benchmark": "ts-node --transpile-only test/benchmark.ts",
"build": "del-cli ./dist && tsc",
"compile-parser": "nearleyc src/grammar.ne --out ./src/grammar.ts && sed -i '' 's/loc?: number/loc: number/g' src/grammar.ts",
"dev": "tsc --watch",
"lint": "eslint ./src ./test && tsc --noEmit",
"test": "NODE_ENV=test ava --serial --verbose"
"test": "NODE_ENV=test ava --serial --verbose",
"watch": "npm-watch"
},
"typings": "./dist/src/Liqe.d.ts",
"version": "1.0.0"
"version": "1.0.0",
"watch": {
"compile-parser": "src/grammar.ne"
}
}
29 changes: 7 additions & 22 deletions src/Liqe.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
export {
filter,
} from './filter';
export {
highlight,
} from './highlight';
export {
parse,
} from './parse';
export {
test,
} from './test';
export { LiqeError, SyntaxError } from './errors';
export { filter } from './filter';
export { highlight } from './highlight';
export { isSafeUnquotedExpression } from './isSafeUnquotedExpression';
export { parse } from './parse';
export { serialize } from './serialize';
export { test } from './test';
export {
BooleanOperatorToken,
ComparisonOperatorToken,
Expand All @@ -29,13 +24,3 @@ export {
TagToken,
UnaryOperatorToken,
} from './types';
export {
LiqeError,
SyntaxError,
} from './errors';
export {
serialize,
} from './serialize';
export {
isSafeUnquotedExpression,
} from './isSafeUnquotedExpression';
7 changes: 3 additions & 4 deletions src/convertWildcardToRegex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ const WILDCARD_RULE = /(\*+)|(\?)/g;

export const convertWildcardToRegex = (pattern: string): RegExp => {
return new RegExp(
pattern
.replace(WILDCARD_RULE, (_match, p1) => {
return p1 ? '(.+?)' : '(.)';
}),
pattern.replaceAll(WILDCARD_RULE, (_match, p1) => {
return p1 ? '(.+?)' : '(.)';
}),
);
};
8 changes: 2 additions & 6 deletions src/createGetValueFunctionBody.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import {
isSafePath,
} from './isSafePath';
import { isSafePath } from './isSafePath';

export const createGetValueFunctionBody = (path: string): string => {
if (!isSafePath(path)) {
Expand All @@ -9,7 +7,5 @@ export const createGetValueFunctionBody = (path: string): string => {

const body = 'return subject' + path;

return body
.replace(/(\.(\d+))/g, '.[$2]')
.replace(/\./g, '?.');
return body.replaceAll(/(\.(\d+))/g, '.[$2]').replaceAll('.', '?.');
};
40 changes: 20 additions & 20 deletions src/createStringTest.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import {
convertWildcardToRegex,
} from './convertWildcardToRegex';
import {
escapeRegexString,
} from './escapeRegexString';
import {
parseRegex,
} from './parseRegex';
import type {
LiqeQuery,
} from './types';
import { convertWildcardToRegex } from './convertWildcardToRegex';
import { escapeRegexString } from './escapeRegexString';
import { parseRegex } from './parseRegex';
import { type LiqeQuery } from './types';

type RegExpCache = Record<string, RegExp>;

Expand All @@ -19,10 +11,11 @@ const createRegexTest = (regexCache: RegExpCache, regex: string) => {
if (regexCache[regex]) {
rule = regexCache[regex];
} else {
rule = regexCache[regex] = parseRegex(regex);
rule = parseRegex(regex);
regexCache[regex] = rule;
}

return (subject: string): string | false => {
return (subject: string): false | string => {
return subject.match(rule)?.[0] ?? false;
};
};
Expand All @@ -32,9 +25,7 @@ export const createStringTest = (regexCache: RegExpCache, ast: LiqeQuery) => {
throw new Error('Expected a tag expression.');
}

const {
expression,
} = ast;
const { expression } = ast;

if (expression.type === 'RangeExpression') {
throw new Error('Unexpected range expression.');
Expand All @@ -50,9 +41,18 @@ export const createStringTest = (regexCache: RegExpCache, ast: LiqeQuery) => {

const value = String(expression.value);

if ((value.includes('*') || value.includes('?')) && expression.quoted === false) {
return createRegexTest(regexCache, String(convertWildcardToRegex(value)) + 'ui');
if (
(value.includes('*') || value.includes('?')) &&
expression.quoted === false
) {
return createRegexTest(
regexCache,
String(convertWildcardToRegex(value)) + 'ui',
);
} else {
return createRegexTest(regexCache, '/(' + escapeRegexString(value) + ')/' + (expression.quoted ? 'u' : 'ui'));
return createRegexTest(
regexCache,
'/(' + escapeRegexString(value) + ')/' + (expression.quoted ? 'u' : 'ui'),
);
}
};
8 changes: 2 additions & 6 deletions src/errors.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
/* eslint-disable fp/no-class */

import {
ExtendableError,
} from 'ts-error';
import { ExtendableError } from 'ts-error';

export class LiqeError extends ExtendableError {}

export class SyntaxError extends LiqeError {
public constructor (
public constructor(
public message: string,
public offset: number,
public line: number,
Expand Down
4 changes: 1 addition & 3 deletions src/escapeRegexString.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@ const ESCAPE_RULE = /[$()*+.?[\\\]^{|}]/g;
const DASH_RULE = /-/g;

export const escapeRegexString = (subject: string): string => {
return subject
.replace(ESCAPE_RULE, '\\$&')
.replace(DASH_RULE, '\\x2d');
return subject.replaceAll(ESCAPE_RULE, '\\$&').replaceAll(DASH_RULE, '\\x2d');
};
13 changes: 3 additions & 10 deletions src/filter.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import {
internalFilter,
} from './internalFilter';
import type {
LiqeQuery,
} from './types';
import { internalFilter } from './internalFilter';
import { type LiqeQuery } from './types';

export const filter = <T extends Object>(
ast: LiqeQuery,
data: readonly T[],
): readonly T[] => {
return internalFilter(
ast,
data,
);
return internalFilter(ast, data);
};
Loading

0 comments on commit 4200642

Please sign in to comment.