Skip to content

Commit

Permalink
Improve forbidden texts
Browse files Browse the repository at this point in the history
1. Allow forbidden texts to be regexes
2. Update `check(` so require a function-like calling syntax
3. Remove `@glimmer/syntax` from `IGNORED_DIRS` by avoiding using
   `check` as an internal method.
  • Loading branch information
wycats committed Nov 3, 2024
1 parent 0d5ec41 commit 57d9118
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions bin/build-verify.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ const FORBIDDEN = [
/**
* These are for local VM debugging and development, and are not meant to make it to real code
*/
'check(',
/[^.]check\(/,
'CheckInterface',
'CheckOr',
'CheckFunction',
'CheckObject',
];

const IGNORED_DIRS = [`@glimmer/syntax`, `@glimmer/debug`];
const IGNORED_DIRS = [`@glimmer/debug`];

let files = await globby(resolve(currentDir, '../../packages/**/dist/**/index.js'), {
ignore: ['node_modules', '**/node_modules'],
Expand All @@ -41,7 +41,7 @@ for (let filePath of files) {
let content = file.toString();

for (let searchFor of FORBIDDEN) {
if (content.includes(searchFor)) {
if (content.match(searchFor)) {
errors.push({ filePath, found: searchFor });
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/@glimmer/syntax/lib/source/loc/match.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ type ExhaustiveCheck<Out, In extends Matches, Removed extends Matches> = Exclude
export type MatchFn<Out> = (left: PositionData, right: PositionData) => Out;

interface ExhaustiveMatcher<Out> {
check(): MatchFn<Out>;
validate(): MatchFn<Out>;
}

export function match<Out>(callback: (m: Matcher<Out>) => ExhaustiveMatcher<Out>): MatchFn<Out> {
return callback(new Matcher()).check();
return callback(new Matcher()).validate();
}

class Matcher<Out, M extends Matches = Matches> {
Expand All @@ -112,7 +112,7 @@ class Matcher<Out, M extends Matches = Matches> {
/**
* You didn't exhaustively match all possibilities.
*/
protected check(): MatchFn<Out> {
protected validate(): MatchFn<Out> {
return (left, right) => this.matchFor(left.kind, right.kind)(left, right);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/@glimmer/syntax/lib/source/loc/offset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class SourceOffset {
} else {
const result = charPos.offset + by;

if (charPos.source.check(result)) {
if (charPos.source.validate(result)) {
return new CharPosition(charPos.source, result).wrap();
} else {
return SourceOffset.broken();
Expand Down
2 changes: 1 addition & 1 deletion packages/@glimmer/syntax/lib/source/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class Source {
/**
* Validate that the character offset represents a position in the source string.
*/
check(offset: number): boolean {
validate(offset: number): boolean {
return offset >= 0 && offset <= this.source.length;
}

Expand Down

0 comments on commit 57d9118

Please sign in to comment.