Skip to content

Commit

Permalink
enable unicorn/prefer-regexp-test rule
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaMachina committed Feb 25, 2023
1 parent c4b480e commit 73c54fe
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ module.exports = {
'always',
{ enforceForIfStatements: true },
],
'unicorn/prefer-regexp-test': 'error',
'unicorn/prefer-export-from': ['error', { ignoreUsedVariables: true }],
'unicorn/throw-new-error': 'error',
'unicorn/prefer-includes': 'error',
Expand Down
3 changes: 2 additions & 1 deletion packages/graphql-language-service/src/parser/RuleHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function list(ofRule: Rule | string, separator?: string | Rule): Rule {
return { ofRule, isList: true, separator };
}

// An constraint described as `but not` in the GraphQL spec.
// A constraint described as `but not` in the GraphQL spec.
export function butNot(rule: Rule, exclusions: Array<Rule>) {
const ruleMatch = rule.match;
rule.match = token => {
Expand All @@ -31,6 +31,7 @@ export function butNot(rule: Rule, exclusions: Array<Rule>) {
}
return (
check &&
// eslint-disable-next-line unicorn/prefer-regexp-test -- false positive exclusion is not string
exclusions.every(exclusion => exclusion.match && !exclusion.match(token))
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ describe('list', () => {
describe('butNot', () => {
const rule = {
match: token =>
token.kind === 'Name' &&
Boolean(token.value.match(/^[_A-Za-z][_0-9A-Za-z]*/)),
token.kind === 'Name' && /^[_A-Za-z][_0-9A-Za-z]*/.test(token.value),
};

const exclusionRules = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ function getToken(
options: ParserOptions,
): string {
if (state.inBlockstring) {
// eslint-disable-next-line unicorn/prefer-regexp-test -- false positive stream is not string
if (stream.match(/.*"""/)) {
state.inBlockstring = false;
return 'string';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class GraphQLContentProvider implements TextDocumentContentProvider {
});
}
validUrlFromSchema(pathOrUrl: string) {
return Boolean(pathOrUrl.match(/^https?:\/\//g));
return /^https?:\/\//.test(pathOrUrl);
}
reportError(message: string) {
this.outputChannel.appendLine(message);
Expand Down

0 comments on commit 73c54fe

Please sign in to comment.