Skip to content

Commit

Permalink
refactor: correction of minor details (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
ren-yamanashi authored Jan 25, 2025
1 parent d847a59 commit a990fee
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ DIST_DIR="dist"
TYPES_DIR="${DIST_DIR}/types"

# build types
npx tsc -p tsconfig.build.json || exit 1
npx tsc -p tsconfig.build.json

# Delete unnecessary files (other than those related to index.d.ts)
find ${DIST_DIR} -mindepth 1 ! -name 'index.d.ts' ! -name 'index.d.ts.map' -exec rm -rf {} +
Expand All @@ -20,7 +20,7 @@ mv ${DIST_DIR}/index.d.ts ${TYPES_DIR}/
mv ${DIST_DIR}/index.d.ts.map ${TYPES_DIR}/

# build
pkgroll --tsconfig=tsconfig.build.json || exit 1
pkgroll --tsconfig=tsconfig.build.json

# restore type definition files
mv ${TYPES_DIR}/index.d.ts ${DIST_DIR}/
Expand Down
14 changes: 7 additions & 7 deletions src/types/symbolFlags.ts → src/constants/tsInternalFlags.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/**
* Implementing `SymbolFlags` defined in typescript on your own, in order not to include TypeScript in dependencies
*/
export enum SymbolFlags {
Class = 32,
}
export const SYMBOL_FLAGS = {
CLASS: 32,
} as const;

/**
* Implementing `SyntaxKind` defined in typescript on your own, in order not to include TypeScript in dependencies
*/
export enum SyntaxKind {
ClassDeclaration = 263,
Constructor = 176,
}
export const SYNTAX_KIND = {
CLASS_DECLARATION: 263,
CONSTRUCTOR: 176,
} as const;
4 changes: 2 additions & 2 deletions src/rules/no-class-in-interface.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AST_NODE_TYPES, ESLintUtils } from "@typescript-eslint/utils";

import { SymbolFlags } from "../types/symbolFlags";
import { SYMBOL_FLAGS } from "../constants/tsInternalFlags";

/**
* Enforces the use of interface types instead of class in interface properties
Expand Down Expand Up @@ -38,7 +38,7 @@ export const noClassInInterface = ESLintUtils.RuleCreator.withoutDocs({
if (!type.symbol) continue;

// NOTE: check class type
const isClass = type.symbol.flags === SymbolFlags.Class;
const isClass = type.symbol.flags === SYMBOL_FLAGS.CLASS;
if (!isClass) continue;

context.report({
Expand Down
6 changes: 3 additions & 3 deletions src/rules/no-public-class-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
TSESTree,
} from "@typescript-eslint/utils";

import { SymbolFlags } from "../types/symbolFlags";
import { SYMBOL_FLAGS } from "../constants/tsInternalFlags";
import { isConstructOrStackType } from "../utils/typeCheck";

type Context = TSESLint.RuleContext<"noPublicClassFields", []>;
Expand Down Expand Up @@ -91,7 +91,7 @@ const validateClassMember = (
const type = parserServices.getTypeAtLocation(member);
if (!type.symbol) continue;

const isClass = type.symbol.flags === SymbolFlags.Class;
const isClass = type.symbol.flags === SYMBOL_FLAGS.CLASS;
if (!isClass) continue;

context.report({
Expand Down Expand Up @@ -133,7 +133,7 @@ const validateConstructorParameterProperty = (
const type = parserServices.getTypeAtLocation(param);
if (!type.symbol) continue;

const isClass = type.symbol.flags === SymbolFlags.Class;
const isClass = type.symbol.flags === SYMBOL_FLAGS.CLASS;
if (!isClass) continue;

context.report({
Expand Down
6 changes: 3 additions & 3 deletions src/utils/parseType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
Type,
} from "typescript";

import { SyntaxKind } from "../types/symbolFlags";
import { SYNTAX_KIND } from "../constants/tsInternalFlags";

/**
* Parses type to get the property names of the class constructor.
Expand All @@ -33,7 +33,7 @@ export const getConstructorPropertyNames = (type: Type): string[] => {
const isClassDeclaration = (
declaration: Declaration
): declaration is ClassDeclaration => {
return declaration.kind === SyntaxKind.ClassDeclaration;
return declaration.kind === SYNTAX_KIND.CLASS_DECLARATION;
};

/**
Expand All @@ -42,5 +42,5 @@ const isClassDeclaration = (
const isConstructorDeclaration = (
node: Node
): node is ConstructorDeclaration => {
return node.kind === SyntaxKind.Constructor;
return node.kind === SYNTAX_KIND.CONSTRUCTOR;
};

0 comments on commit a990fee

Please sign in to comment.