Skip to content

Commit

Permalink
Merge branch 'main' into well-known-symbol-property-declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaStevens committed Feb 19, 2023
2 parents 017a4f0 + 0d67346 commit a4664a3
Show file tree
Hide file tree
Showing 21 changed files with 317 additions and 147 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/knip-production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Lint Knip (Production)

on:
push:
branches:
- main
pull_request:

jobs:
knip:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/prepare
- run: pnpm lint:knip:production
2 changes: 1 addition & 1 deletion .github/workflows/knip.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Lint Knip
name: Lint Knip (Development)

on:
push:
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
branches:
- main

permissions:
contents: write

jobs:
release:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -34,7 +37,7 @@ jobs:
}
}
- env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ github.token }}
run: if pnpm run should-semantic-release ; then pnpm release-it --verbose ; fi
- if: always()
name: Recreate branch protection on main
Expand Down
6 changes: 2 additions & 4 deletions knip.jsonc
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"$schema": "https://unpkg.com/knip@next/schema.json",
"entry": "src/index.ts!",
"project": "src/**/*.ts!",
// TODO: /~https://github.com/JoshuaKGoldberg/ts-api-utils/issues/45
"ignore": ["src/nodes/typeGuards/!(*.test).ts"]
"entry": ["src/**/index.ts", "src/**/*.test.ts"],
"project": ["src/**/*.ts"]
}
5 changes: 5 additions & 0 deletions knip.production.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "https://unpkg.com/knip@next/schema.json",
"entry": ["src/**/index.ts!"],
"project": ["src/**/*.ts!", "!src/test/**/*.ts!", "!src/**/*.test.ts!"]
}
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ts-api-utils",
"version": "0.0.22",
"version": "0.0.26",
"description": "Utility functions for working with TypeScript's API. Successor to the wonderful tsutils.",
"repository": {
"type": "git",
Expand Down Expand Up @@ -28,7 +28,8 @@
"format": "prettier \"**/*\" --ignore-unknown",
"format:write": "pnpm format --write",
"lint": "eslint . --max-warnings 0 --report-unused-disable-directives",
"lint:knip": "knip",
"lint:knip": "knip --config knip.jsonc",
"lint:knip:production": "knip --config knip.production.jsonc --production",
"lint:md": "markdownlint \"**/*.md\" \".github/**/*.md\" --rules sentences-per-line",
"lint:package": "npmPkgJsonLint .",
"lint:packages": "pnpm-deduplicate --list",
Expand Down Expand Up @@ -58,7 +59,7 @@
"eslint-plugin-regexp": "^1.12.0",
"eslint-plugin-simple-import-sort": "^10.0.0",
"eslint-plugin-typescript-sort-keys": "^2.1.0",
"eslint-plugin-vitest": "^0.0.32",
"eslint-plugin-vitest": "^0.0.34",
"husky": "^8.0.3",
"jsonc-eslint-parser": "^2.1.0",
"knip": "^1.12.3",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 11 additions & 7 deletions src/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,35 @@

import * as ts from "typescript";

function isFlagSet(obj: { flags: number }, flag: number): boolean {
return (obj.flags & flag) !== 0;
function isFlagSet(allFlags: number, flag: number): boolean {
return (allFlags & flag) !== 0;
}

function isFlagSetOnObject(obj: { flags: number }, flag: number): boolean {
return isFlagSet(obj.flags, flag);
}

export function isModifierFlagSet(
node: ts.Declaration,
flag: ts.ModifierFlags
): boolean {
return (ts.getCombinedModifierFlags(node) & flag) !== 0;
return isFlagSet(ts.getCombinedModifierFlags(node), flag);
}

export const isNodeFlagSet: (node: ts.Node, flag: ts.NodeFlags) => boolean =
isFlagSet;
isFlagSetOnObject;

export function isObjectFlagSet(
objectType: ts.ObjectType,
flag: ts.ObjectFlags
): boolean {
return (objectType.objectFlags & flag) !== 0;
return isFlagSet(objectType.objectFlags, flag);
}

export const isSymbolFlagSet: (
symbol: ts.Symbol,
flag: ts.SymbolFlags
) => boolean = isFlagSet;
) => boolean = isFlagSetOnObject;

export const isTypeFlagSet: (type: ts.Type, flag: ts.TypeFlags) => boolean =
isFlagSet;
isFlagSetOnObject;
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ export * from "./scopes.js";
export * from "./syntax.js";
export * from "./tokens.js";
export * from "./types/getters.js";
export * from "./types/typeGuards.js";
export * from "./types/typeGuards/index.js";
export * from "./types/utilities.js";
20 changes: 13 additions & 7 deletions src/nodes/typeGuards/compound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as ts from "typescript";

import { isSuperExpression } from "./single.js";
import {
isDeclarationName,
isEntityNameExpression,
isJSDocNamespaceBody,
isJsxTagNameExpression,
Expand Down Expand Up @@ -61,14 +62,19 @@ export function isJsxTagNamePropertyAccess(
);
}

/**
* @remarks This always returns true.
* @see /~https://github.com/JoshuaKGoldberg/ts-api-utils/pull/16#discussion_r1106579774
*/
export function isNamedDeclaration(
export interface NamedDeclarationWithName extends ts.NamedDeclaration {
name: ts.DeclarationName;
}

export function isNamedDeclarationWithName(
node: ts.Declaration
): node is ts.NamedDeclaration {
return true;
): node is NamedDeclarationWithName {
return (
"name" in node &&
node.name !== undefined &&
node.name !== null &&
isDeclarationName(node.name as ts.Node)
);
}

export function isNamespaceDeclaration(
Expand Down
Loading

0 comments on commit a4664a3

Please sign in to comment.