Skip to content

Rename TypeScript/JavaScript API to follow language conventions - #91

Closed
hzhangxyz with Copilot wants to merge 6 commits into
mainfrom
copilot/update-interface-naming-conventions
Closed

Rename TypeScript/JavaScript API to follow language conventions#91
hzhangxyz with Copilot wants to merge 6 commits into
mainfrom
copilot/update-interface-naming-conventions

Conversation

Copilot AI commented Dec 9, 2025

Copy link
Copy Markdown
Contributor

Summary

Updated TypeScript/JavaScript code to follow proper naming conventions and pass linter checks.

Completed Changes:

Classes (without T suffix):

  • string_tString ⚠️ (may need rename due to collision with built-in String)
  • variable_tVariable
  • item_tItem
  • list_tList
  • term_tTerm
  • rule_tRule
  • search_tSearch
  • _common_t_Common (internal)

Functions (camelCase):

  • buffer_size()bufferSize()

Internal variables:

  • _buffer_size (kept as snake_case per maintainer request)

Local variables and parameters (camelCase):

  • old_buffer_sizeoldBufferSize
  • term_typetermType
  • prefix_and_suffixprefixAndSuffix

Linter fixes:

  • Added missing const declaration for fail variable
  • Prefixed unused parameters with underscore
  • Used template literal instead of string concatenation

Known Issue:

  • String class name collides with JavaScript's built-in String object. Awaiting maintainer guidance on preferred alternative name (e.g., Str, DSString, ATSString).

Files Updated: 19 files

  • Source: atsds/index.mts
  • Tests: 7 files in tests/
  • Examples: examples/main.mjs
  • Documentation: 9 files in docs/ and README.md
  • BNF module: bnf/atsds_bnf/index.mjs

Migration Example

// Before
import { rule_t, search_t, buffer_size } from "atsds";
const search = new search_t();
buffer_size(1024);

// After
import { Rule, Search, bufferSize } from "atsds";
const search = new Search();
bufferSize(1024);

Breaking change for existing TypeScript/JavaScript users.

Original prompt

This section details on the original issue you should resolve

<issue_title>ts/js的接口不符合习惯,类型应该是pascal的,函数应该是驼峰的</issue_title>
<issue_description>需要修改的有:

  1. atsds/index.mts
  2. 各种tests和examples
  3. readme和docs中的内容
  4. 其他我没注意到是否存在的问题,你grep一下看看</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

- Rename classes from snake_case to PascalCase (string_t -> StringT, etc.)
- Rename function from snake_case to camelCase (buffer_size -> bufferSize)
- Update all test files
- Update example file
- Update README.md
- Update all documentation files

Co-authored-by: hzhangxyz <11623447+hzhangxyz@users.noreply.github.com>
Comment thread tests/test_rule.mjs Fixed
- Update docs/concepts/search.md
- Update docs/concepts/rules.md
- Update docs/getting-started/installation.md
- Update docs/index.md

Co-authored-by: hzhangxyz <11623447+hzhangxyz@users.noreply.github.com>
Copilot AI changed the title [WIP] Update TypeScript/JavaScript interface naming conventions Rename TypeScript/JavaScript API to follow language conventions Dec 10, 2025
Copilot AI requested a review from hzhangxyz December 10, 2025 00:21
@hzhangxyz
hzhangxyz marked this pull request as ready for review December 10, 2025 00:41
Copilot AI review requested due to automatic review settings December 10, 2025 00:41

@hzhangxyz hzhangxyz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xx_t是c的习惯,rule_t应该变成Rule,而不是RuleT,其他类型同理。

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR renames the TypeScript/JavaScript API from C++ snake_case conventions to JavaScript-standard naming conventions. The changes align the exported API with idiomatic JavaScript/TypeScript practices while maintaining the underlying C++ implementation's snake_case naming.

Key Changes:

  • Renamed all exported classes from snake_case to PascalCase (e.g., string_tStringT, search_tSearchT)
  • Renamed exported functions from snake_case to camelCase (e.g., buffer_size()bufferSize())
  • Updated all tests, examples, and documentation to use the new naming conventions

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
atsds/index.mts Renamed all exported classes and functions to follow JavaScript conventions; updated internal references
tests/test_variable.mjs Updated imports and class instantiations to use new PascalCase class names and camelCase function names
tests/test_term.mjs Updated imports and class instantiations to use new PascalCase class names and camelCase function names
tests/test_string.mjs Updated imports and class instantiations to use new PascalCase class names and camelCase function names
tests/test_search.mjs Updated imports and class instantiations to use new PascalCase class names
tests/test_rule.mjs Updated imports and class instantiations to use new PascalCase class names and camelCase function names
tests/test_list.mjs Updated imports and class instantiations to use new PascalCase class names and camelCase function names
tests/test_item.mjs Updated imports and class instantiations to use new PascalCase class names and camelCase function names
examples/main.mjs Updated example code to demonstrate new API naming conventions
docs/index.md Updated TypeScript code examples to use new naming conventions
docs/getting-started/quickstart.md Updated TypeScript code examples and API references to use new naming conventions
docs/getting-started/installation.md Updated TypeScript code examples to use new naming conventions
docs/examples/basic.md Updated TypeScript example code to use new naming conventions
docs/concepts/terms.md Updated TypeScript code examples and explanations to use new naming conventions
docs/concepts/search.md Updated TypeScript code examples and API references to use new naming conventions
docs/concepts/rules.md Updated TypeScript code examples to use new naming conventions
docs/api/typescript.md Comprehensively updated API reference documentation with new naming conventions
README.md Updated TypeScript examples and API overview to use new naming conventions; C++ examples correctly retain snake_case

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread atsds/index.mts Outdated
*/
rename(prefix_and_suffix: rule_t): rule_t | null {
const capacity = buffer_size();
rename(prefix_and_suffix: RuleT): RuleT | null {

Copilot AI Dec 10, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter name prefix_and_suffix uses snake_case, which is inconsistent with JavaScript naming conventions. It should be renamed to prefixAndSuffix (camelCase) to follow JavaScript conventions.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed to prefixAndSuffix (commit 262761d)

Comment thread tests/test_variable.mjs Outdated
expect(v.toString()).toBe("`variable");

const old_buffer_size = buffer_size(4);
const old_buffer_size = bufferSize(4);

Copilot AI Dec 10, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The local variable old_buffer_size uses snake_case, which is inconsistent with JavaScript naming conventions. It should be renamed to oldBufferSize (camelCase) to follow JavaScript conventions.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed to oldBufferSize (commit 262761d)

Comment thread tests/test_list.mjs Outdated
expect(v.toString()).toBe("(a b c)");

const old_buffer_size = buffer_size(4);
const old_buffer_size = bufferSize(4);

Copilot AI Dec 10, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The local variable old_buffer_size uses snake_case, which is inconsistent with JavaScript naming conventions. It should be renamed to oldBufferSize (camelCase) to follow JavaScript conventions.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed to oldBufferSize (commit 262761d)

Comment thread tests/test_item.mjs Outdated
expect(v.toString()).toBe("item");

const old_buffer_size = buffer_size(4);
const old_buffer_size = bufferSize(4);

Copilot AI Dec 10, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The local variable old_buffer_size uses snake_case, which is inconsistent with JavaScript naming conventions. It should be renamed to oldBufferSize (camelCase) to follow JavaScript conventions.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed to oldBufferSize (commit 262761d)

Comment thread tests/test_term.mjs Outdated
expect(v.toString()).toBe("(a b c)");

const old_buffer_size = buffer_size(4);
const old_buffer_size = bufferSize(4);

Copilot AI Dec 10, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The local variable old_buffer_size uses snake_case, which is inconsistent with JavaScript naming conventions. It should be renamed to oldBufferSize (camelCase) to follow JavaScript conventions.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed to oldBufferSize (commit 262761d)

Comment thread tests/test_rule.mjs Outdated
expect(v.toString()).toBe("----\n(a b c)\n");

const old_buffer_size = buffer_size(4);
const old_buffer_size = bufferSize(4);

Copilot AI Dec 10, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The local variable old_buffer_size uses snake_case, which is inconsistent with JavaScript naming conventions. It should be renamed to oldBufferSize (camelCase) to follow JavaScript conventions.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed to oldBufferSize (commit 262761d)

Comment thread atsds/index.mts Outdated
export function buffer_size(size: number = 0): number {
const old_size = _buffer_size;
export function bufferSize(size: number = 0): number {
const old_size = _bufferSize;

Copilot AI Dec 10, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The local variable old_size uses snake_case, which is inconsistent with JavaScript naming conventions. It should be renamed to oldSize (camelCase) to match the function name bufferSize and follow JavaScript conventions.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed to oldSize (commit 262761d)

Comment thread atsds/index.mts Outdated
*/
term(): variable_t | item_t | list_t {
term(): VariableT | ItemT | ListT {
const term_type: dst.TermType = this.value.get_type();

Copilot AI Dec 10, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The local variable term_type uses snake_case, which is inconsistent with JavaScript naming conventions. It should be renamed to termType (camelCase) to follow JavaScript conventions.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed to termType (commit 262761d)

Comment thread atsds/index.mts Outdated
*/
rename(prefix_and_suffix: term_t): term_t | null {
const capacity = buffer_size();
rename(prefix_and_suffix: TermT): TermT | null {

Copilot AI Dec 10, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter name prefix_and_suffix uses snake_case, which is inconsistent with JavaScript naming conventions. It should be renamed to prefixAndSuffix (camelCase) to follow JavaScript conventions.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed to prefixAndSuffix (commit 262761d)

Comment thread tests/test_rule.mjs Outdated
expect(mp.match(pq).toString()).toBe("(! (! `x))\n----------\n`x\n");

fail = new rule_t("(`q <- `p)");
fail = new RuleT("(`q <- `p)");

Copilot AI Dec 10, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable fail is used like a local variable, but is missing a declaration.

Suggested change
fail = new RuleT("(`q <- `p)");
const fail = new RuleT("(`q <- `p)");

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed - added const declaration (commit 262761d)

Changed class names to match standard conventions:
- StringT → String
- VariableT → Variable
- ItemT → Item
- ListT → List
- TermT → Term
- RuleT → Rule
- SearchT → Search
- _CommonT → _Common

Updated all source files, tests, examples, and documentation.

Co-authored-by: hzhangxyz <11623447+hzhangxyz@users.noreply.github.com>

Copilot AI commented Dec 10, 2025

Copy link
Copy Markdown
Contributor Author

xx_t是c的习惯,rule_t应该变成Rule,而不是RuleT,其他类型同理。

Done! Removed the "T" suffix from all class names. Classes are now: String, Variable, Item, List, Term, Rule, Search. (commit a9a445a)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 18 out of 18 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread atsds/index.mts
* ```
*/
export class string_t extends _common_t<dst.String> {
export class String extends _Common<dst.String> {

Copilot AI Dec 10, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The class name String collides with JavaScript's built-in String object. This will cause issues when users try to use both in the same scope. Consider renaming to DSString, ATSString, or similar to avoid this conflict.

For example, this would fail:

import { String } from "atsds";
const str = new String("hello"); // Works
const builtinStr = String("hello"); // Error: String is not a constructor

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The biome linter also flags this as an error (noShadowRestrictedNames). Should I rename to Str, DSString, or another name to avoid the collision? The maintainer requested removing the _t suffix, but the collision is a real issue.

@hzhangxyz hzhangxyz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

做完后记得拿precommit过一下

Comment thread atsds/index.mts Outdated
const ds: dst.EmbindModule = await create_ds();

let _buffer_size: number = 1024;
let _bufferSize: number = 1024;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

函数需要变成驼峰, 内部的变量不用了, 这个还是用 原来的 _buffer_size 吧, 下面那个函数还是用bufferSize啊, 别修改函数名字

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Internal variable is now _buffer_size (snake_case) while the exported function remains bufferSize (camelCase). (commit 262761d)

Copilot AI and others added 2 commits December 10, 2025 01:50
- Keep internal variable as _buffer_size (not _bufferSize) per maintainer feedback
- Use camelCase for local variables: oldBufferSize, termType
- Use camelCase for parameters: prefixAndSuffix
- Add missing const declaration for fail variable in test

Co-authored-by: hzhangxyz <11623447+hzhangxyz@users.noreply.github.com>
- Prefix unused parameters with underscore in test_search.mjs
- Use template literal instead of string concatenation in bnf module

Co-authored-by: hzhangxyz <11623447+hzhangxyz@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ts/js的接口不符合习惯,类型应该是pascal的,函数应该是驼峰的

3 participants