From d569bff8a44fc30cf71eabdefd74ede575cd5510 Mon Sep 17 00:00:00 2001 From: Arnaud Riess Date: Mon, 22 Jun 2026 16:04:00 +0200 Subject: [PATCH 1/4] =?UTF-8?q?=E2=9C=A8=20NEW:=20Add=20TypeScript=20suppo?= =?UTF-8?q?rt=20for=20discovery=20and=20analyse=20(#69)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/source/components/analyse.rst | 2 +- docs/source/components/configuration.rst | 7 +- docs/source/components/discover.rst | 10 ++ docs/source/development/change_log.rst | 6 +- pyproject.toml | 1 + src/sphinx_codelinks/analyse/utils.py | 13 +++ .../source_discover/config.py | 2 + tests/data/discover_fixtures.json | 44 +++++++-- tests/data/typescript/demo.ts | 17 ++++ tests/test_analyse.py | 24 ++++- tests/test_analyse_utils.py | 98 +++++++++++++++++++ tests/test_source_discover.py | 10 +- tests/test_src_trace.py | 2 +- 13 files changed, 222 insertions(+), 14 deletions(-) create mode 100644 tests/data/typescript/demo.ts diff --git a/docs/source/components/analyse.rst b/docs/source/components/analyse.rst index 2b47c5a..e00f1f1 100644 --- a/docs/source/components/analyse.rst +++ b/docs/source/components/analyse.rst @@ -47,7 +47,7 @@ Limitations **Current Limitations:** -- **Language Support**: C/C++ (``//``, ``/* */``), C# (``//``, ``/* */``, ``///``), Python (``#``), YAML (``#``) and Rust (``//``, ``/* */``, ``///``) comment styles are supported +- **Language Support**: C/C++ (``//``, ``/* */``), C# (``//``, ``/* */``, ``///``), TypeScript (``//``, ``/* */``), Python (``#``), YAML (``#``) and Rust (``//``, ``/* */``, ``///``) comment styles are supported - **Single Comment Style**: Each analysis run processes only one comment style at a time Extraction Examples diff --git a/docs/source/components/configuration.rst b/docs/source/components/configuration.rst index 0d354dd..0f15c9d 100644 --- a/docs/source/components/configuration.rst +++ b/docs/source/components/configuration.rst @@ -271,7 +271,7 @@ Specifies the comment syntax style used in the source code files. This determine **Type:** ``str`` **Default:** ``"cpp"`` -**Supported values:** ``"cpp"``, ``"python"``, ``"cs"``, ``"yaml"``, ``"rust"`` +**Supported values:** ``"cpp"``, ``"python"``, ``"cs"``, ``"ts"``, ``"yaml"``, ``"rust"`` .. code-block:: toml @@ -304,6 +304,11 @@ Specifies the comment syntax style used in the source code files. This determine ``/* */`` (multi-line), ``///`` (XML doc comments) - ``.cs`` + * - TypeScript + - ``"ts"`` + - ``//`` (single-line), + ``/* */`` (multi-line) + - ``.ts``, ``.tsx`` * - YAML - ``"yaml"`` - ``#`` (single-line) diff --git a/docs/source/components/discover.rst b/docs/source/components/discover.rst index 33a2d52..8b78645 100644 --- a/docs/source/components/discover.rst +++ b/docs/source/components/discover.rst @@ -38,3 +38,13 @@ Usage Examples include = [] exclude = ["tests/**", "setup.py"] comment_type = "python" + +**TypeScript Project:** + +.. code-block:: toml + + [source_discover] + src_dir = "./frontend" + include = ["**/*.ts", "**/*.tsx"] + exclude = ["**/*.test.ts", "**/*.spec.ts"] + comment_type = "ts" diff --git a/docs/source/development/change_log.rst b/docs/source/development/change_log.rst index e9f20e2..3847ddc 100644 --- a/docs/source/development/change_log.rst +++ b/docs/source/development/change_log.rst @@ -7,6 +7,10 @@ Upcoming -------- - ⬆️ Support and test sphinx-needs v5-8 +- ✨ Added TypeScript comment type support for source discovery and analysis. + + TypeScript files can now be processed using ``comment_type = "ts"``. + Source discovery supports both ``.ts`` and ``.tsx`` extensions by default. .. _`release:1.2.0`: @@ -31,7 +35,6 @@ New and Improved Warning messages now include more context to help diagnose parsing issues. - 📚 Added traceability page to the documentation. - - 📚 Added ``features.rst`` page documenting the full feature set with source tracing. Fixes @@ -41,7 +44,6 @@ Fixes Leading and trailing spaces in extracted marker content are now correctly stripped. - .. _`release:1.1.0`: 1.1.0 diff --git a/pyproject.toml b/pyproject.toml index 93cb917..8dc6e87 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,6 +28,7 @@ dependencies = [ # https://github.com/tree-sitter/py-tree-sitter/issues/386#issuecomment-3101430799 "tree-sitter~=0.25.1", "tree-sitter-c-sharp>=0.23.1", + "tree-sitter-typescript>=0.23.2", "tree-sitter-yaml>=0.7.1", "tree-sitter-rust>=0.23.0", ] diff --git a/src/sphinx_codelinks/analyse/utils.py b/src/sphinx_codelinks/analyse/utils.py index 5a11fdd..b96cd5c 100644 --- a/src/sphinx_codelinks/analyse/utils.py +++ b/src/sphinx_codelinks/analyse/utils.py @@ -19,6 +19,13 @@ # @C and C++ Scope Node Types, IMPL_C_2, impl, [FE_C_SUPPORT, FE_CPP] CommentType.cpp: {"function_definition", "class_definition"}, CommentType.cs: {"method_declaration", "class_declaration", "property_declaration"}, + CommentType.ts: { + "function_declaration", + "class_declaration", + "method_definition", + "lexical_declaration", + "variable_declaration", + }, CommentType.yaml: {"block_mapping_pair", "block_sequence_item", "document"}, # @Rust Scope Node Types, IMPL_RUST_2, impl, [FE_RUST]; CommentType.rust: { @@ -55,6 +62,7 @@ """ CPP_QUERY = """(comment) @comment""" C_SHARP_QUERY = """(comment) @comment""" +TYPE_SCRIPT_QUERY = """(comment) @comment""" YAML_QUERY = """(comment) @comment""" RUST_QUERY = """ (line_comment) @comment @@ -94,6 +102,11 @@ def init_tree_sitter(comment_type: CommentType) -> tuple[Parser, Query]: parsed_language = Language(tree_sitter_c_sharp.language()) query = Query(parsed_language, C_SHARP_QUERY) + elif comment_type == CommentType.ts: + import tree_sitter_typescript # noqa: PLC0415 + + parsed_language = Language(tree_sitter_typescript.language_typescript()) + query = Query(parsed_language, TYPE_SCRIPT_QUERY) elif comment_type == CommentType.yaml: import tree_sitter_yaml # noqa: PLC0415 diff --git a/src/sphinx_codelinks/source_discover/config.py b/src/sphinx_codelinks/source_discover/config.py index 51ae3c0..45a51fd 100644 --- a/src/sphinx_codelinks/source_discover/config.py +++ b/src/sphinx_codelinks/source_discover/config.py @@ -9,6 +9,7 @@ "cpp": ["c", "ci", "cpp", "cc", "cxx", "h", "hpp", "hxx", "hh", "ihl"], "python": ["py"], "cs": ["cs"], + "ts": ["ts", "tsx"], "yaml": ["yml", "yaml"], "rust": ["rs"], } @@ -18,6 +19,7 @@ class CommentType(str, Enum): python = "python" cpp = "cpp" cs = "cs" + ts = "ts" yaml = "yaml" # @Support Rust style comments, IMPL_RUST_1, impl, [FE_RUST]; rust = "rust" diff --git a/tests/data/discover_fixtures.json b/tests/data/discover_fixtures.json index 7ffd5d4..738c619 100644 --- a/tests/data/discover_fixtures.json +++ b/tests/data/discover_fixtures.json @@ -75,7 +75,9 @@ "config": { "src_dir": "src", "include": [], - "exclude": ["**/build/**"], + "exclude": [ + "**/build/**" + ], "gitignore": false, "comment_type": "cpp" }, @@ -94,7 +96,9 @@ }, "config": { "src_dir": "src", - "include": ["**/*.cpp"], + "include": [ + "**/*.cpp" + ], "exclude": [], "gitignore": false, "comment_type": "cpp" @@ -115,8 +119,12 @@ }, "config": { "src_dir": "src", - "include": ["**/*.cpp"], - "exclude": ["**/test_*.cpp"], + "include": [ + "**/*.cpp" + ], + "exclude": [ + "**/test_*.cpp" + ], "gitignore": false, "comment_type": "cpp" }, @@ -280,7 +288,9 @@ "config": { "src_dir": "src", "include": [], - "exclude": ["**/test_*.cpp"], + "exclude": [ + "**/test_*.cpp" + ], "gitignore": true, "comment_type": "cpp" }, @@ -386,5 +396,27 @@ "expected": [ "src/Program.cs" ] + }, + { + "name": "typescript_comment_type", + "description": "TypeScript comment type discovers .ts and .tsx files", + "git_init": false, + "files": { + "src/main.ts": "// main", + "src/component.tsx": "// component", + "src/main.cpp": "// not ts", + "src/util.py": "# not ts" + }, + "config": { + "src_dir": "src", + "include": [], + "exclude": [], + "gitignore": false, + "comment_type": "ts" + }, + "expected": [ + "src/component.tsx", + "src/main.ts" + ] } -] +] \ No newline at end of file diff --git a/tests/data/typescript/demo.ts b/tests/data/typescript/demo.ts new file mode 100644 index 0000000..66aade0 --- /dev/null +++ b/tests/data/typescript/demo.ts @@ -0,0 +1,17 @@ +// regular comment +function testA() { + // @type,TS_REQ_002,TypeScript one-line test + return 1; +} + +/* regular block comment */ +const testB = () => { + return 2; +}; + +// another comment +class Demo { + methodA() { + return 3; + } +} diff --git a/tests/test_analyse.py b/tests/test_analyse.py index 6e6c2a7..500451c 100644 --- a/tests/test_analyse.py +++ b/tests/test_analyse.py @@ -55,7 +55,7 @@ def test_analyse(src_dir, src_paths, tmp_path, snapshot_marks): @pytest.mark.parametrize( - "src_dir, src_paths , oneline_comment_style, result", + "src_dir, src_paths, comment_type, oneline_comment_style, result", [ ( TEST_DIR / "data" / "dcdc", @@ -65,6 +65,7 @@ def test_analyse(src_dir, src_paths, tmp_path, snapshot_marks): TEST_DIR / "data" / "dcdc" / "discharge" / "demo_3.cpp", TEST_DIR / "data" / "dcdc" / "supercharge.cpp", ], + "cpp", ONELINE_COMMENT_STYLE, { "num_src_files": 4, @@ -79,6 +80,7 @@ def test_analyse(src_dir, src_paths, tmp_path, snapshot_marks): [ TEST_DIR / "data" / "oneline_comment_basic" / "basic_oneliners.c", ], + "cpp", ONELINE_COMMENT_STYLE, { "num_src_files": 1, @@ -94,6 +96,7 @@ def test_analyse(src_dir, src_paths, tmp_path, snapshot_marks): [ TEST_DIR / "data" / "oneline_comment_default" / "default_oneliners.c", ], + "cpp", ONELINE_COMMENT_STYLE_DEFAULT, { "num_src_files": 1, @@ -109,6 +112,7 @@ def test_analyse(src_dir, src_paths, tmp_path, snapshot_marks): [ TEST_DIR / "data" / "rust" / "demo.rs", ], + "rust", ONELINE_COMMENT_STYLE_DEFAULT, { "num_src_files": 1, @@ -118,10 +122,25 @@ def test_analyse(src_dir, src_paths, tmp_path, snapshot_marks): "num_oneline_warnings": 0, }, ), + ( + TEST_DIR / "data" / "typescript", + [ + TEST_DIR / "data" / "typescript" / "demo.ts", + ], + "ts", + ONELINE_COMMENT_STYLE_DEFAULT, + { + "num_src_files": 1, + "num_uncached_files": 1, + "num_cached_files": 0, + "num_comments": 4, + "num_oneline_warnings": 0, + }, + ), ], ) def test_analyse_oneline_needs( - tmp_path, src_dir, src_paths, oneline_comment_style, result + tmp_path, src_dir, src_paths, comment_type, oneline_comment_style, result ): src_analyse_config = SourceAnalyseConfig( src_files=src_paths, @@ -130,6 +149,7 @@ def test_analyse_oneline_needs( get_oneline_needs=True, get_rst=False, oneline_comment_style=oneline_comment_style, + comment_type=comment_type, ) src_analyse = SourceAnalyse(src_analyse_config) src_analyse.run() diff --git a/tests/test_analyse_utils.py b/tests/test_analyse_utils.py index 207b1f9..c1a2dc8 100644 --- a/tests/test_analyse_utils.py +++ b/tests/test_analyse_utils.py @@ -10,6 +10,7 @@ import tree_sitter_cpp import tree_sitter_python import tree_sitter_rust +import tree_sitter_typescript import tree_sitter_yaml from sphinx_codelinks.analyse import utils @@ -57,6 +58,14 @@ def init_rust_tree_sitter() -> tuple[Parser, Query]: return parser, query +@pytest.fixture(scope="session") +def init_typescript_tree_sitter() -> tuple[Parser, Query]: + parsed_language = Language(tree_sitter_typescript.language_typescript()) + query = Query(parsed_language, utils.TYPE_SCRIPT_QUERY) + parser = Parser(parsed_language) + return parser, query + + @pytest.mark.parametrize( ("code", "result"), [ @@ -365,6 +374,41 @@ def test_find_associated_scope_rust(code, result, init_rust_tree_sitter): assert result in rust_def +@pytest.mark.parametrize( + ("code", "result"), + [ + ( + b""" + // @req-id: need_001 + function dummyFunc1() { + } + """, + "function dummyFunc1()", + ), + ( + b""" + class DummyClass { + // @req-id: need_001 + method1() { + } + } + """, + "method1()", + ), + ], +) +def test_find_associated_scope_typescript(code, result, init_typescript_tree_sitter): + parser, query = init_typescript_tree_sitter + comments = utils.extract_comments(code, parser, query) + node: TreeSitterNode | None = utils.find_associated_scope( + comments[0], CommentType.ts + ) + assert node + assert node.text + ts_def = node.text.decode("utf-8") + assert result in ts_def + + @pytest.mark.parametrize( ("code", "result"), [ @@ -519,6 +563,29 @@ def test_find_next_scope_csharp(code, result, init_csharp_tree_sitter): assert result in func_def +@pytest.mark.parametrize( + ("code", "result"), + [ + ( + b""" + // @req-id: need_001 + function dummyFunc1() { + } + """, + "function dummyFunc1()", + ), + ], +) +def test_find_next_scope_typescript(code, result, init_typescript_tree_sitter): + parser, query = init_typescript_tree_sitter + comments = utils.extract_comments(code, parser, query) + node: TreeSitterNode | None = utils.find_next_scope(comments[0], CommentType.ts) + assert node + assert node.text + func_def = node.text.decode("utf-8") + assert result in func_def + + @pytest.mark.parametrize( ("code", "result"), [ @@ -773,6 +840,37 @@ def test_csharp_comment(code, num_comments, result, init_csharp_tree_sitter): assert comments[0].text.decode("utf-8") == result +@pytest.mark.parametrize( + ("code", "num_comments", "result"), + [ + ( + b""" + // @req-id: need_001 + function dummyFunc1() { + } + """, + 1, + "// @req-id: need_001", + ), + ( + b""" + /* @req-id: need_001 */ + const value = 1; + """, + 1, + "/* @req-id: need_001 */", + ), + ], +) +def test_typescript_comment(code, num_comments, result, init_typescript_tree_sitter): + parser, query = init_typescript_tree_sitter + comments: list[TreeSitterNode] = utils.extract_comments(code, parser, query) + comments.sort(key=lambda x: x.start_point.row) + assert len(comments) == num_comments + assert comments[0].text + assert comments[0].text.decode("utf-8") == result + + @pytest.mark.parametrize( ("code", "num_comments", "result"), [ diff --git a/tests/test_source_discover.py b/tests/test_source_discover.py index 5a6f5c1..30decf4 100644 --- a/tests/test_source_discover.py +++ b/tests/test_source_discover.py @@ -49,7 +49,7 @@ "comment_type": "java", }, [ - "Schema validation error in field 'comment_type': 'java' is not one of ['cpp', 'cs', 'python', 'rust', 'yaml']" + "Schema validation error in field 'comment_type': 'java' is not one of ['cpp', 'cs', 'python', 'rust', 'ts', 'yaml']" ], ), ( @@ -99,6 +99,13 @@ def test_schema_negative(config, msgs): "gitignore": True, "comment_type": "python", }, + { + "src_dir": "/path/to/root", + "exclude": ["exclude1", "exclude2"], + "include": ["include1", "include2"], + "gitignore": True, + "comment_type": "ts", + }, { "src_dir": "/path/to/root", "follow_links": True, @@ -182,6 +189,7 @@ def create_source_files(tmp_path: Path) -> Path: [ ("cpp", len(COMMENT_FILETYPE["cpp"])), ("python", len(COMMENT_FILETYPE["python"])), + ("ts", len(COMMENT_FILETYPE["ts"])), ], ) def test_comment_filetype( diff --git a/tests/test_src_trace.py b/tests/test_src_trace.py index 8e87a71..2ecc3fd 100644 --- a/tests/test_src_trace.py +++ b/tests/test_src_trace.py @@ -58,7 +58,7 @@ [ "Project 'dcdc' has the following errors:", "Schema validation error in field 'exclude': 123 is not of type 'string'", - "Schema validation error in field 'comment_type': 'java' is not one of ['cpp', 'cs', 'python', 'rust', 'yaml']", + "Schema validation error in field 'comment_type': 'java' is not one of ['cpp', 'cs', 'python', 'rust', 'ts', 'yaml']", "Schema validation error in field 'gitignore': '_true' is not of type 'boolean'", "Schema validation error in field 'include': 345 is not of type 'string'", "Schema validation error in field 'src_dir': ['../dcdc'] is not of type 'string'", From 4e9ef51d27534fffd4e67f29487388dd8f44feb8 Mon Sep 17 00:00:00 2001 From: Arnaud Riess Date: Mon, 22 Jun 2026 16:17:25 +0200 Subject: [PATCH 2/4] =?UTF-8?q?=E2=9C=A8=20Update=20changelog:=20Add=20Typ?= =?UTF-8?q?eScript=20comment=20type=20support=20for=20source=20discovery?= =?UTF-8?q?=20and=20analysis?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/source/development/change_log.rst | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/docs/source/development/change_log.rst b/docs/source/development/change_log.rst index fe2e138..4901b69 100644 --- a/docs/source/development/change_log.rst +++ b/docs/source/development/change_log.rst @@ -3,6 +3,14 @@ Changelog ========= +Under development +----------------- + +- ✨ Added TypeScript comment type support for source discovery and analysis. + + TypeScript files can now be processed using ``comment_type = "ts"``. + Source discovery supports both ``.ts`` and ``.tsx`` extensions by default. + .. _`release:1.3.0`: 1.3.0 @@ -23,11 +31,6 @@ New and Improved Comments in JSONC files are now parsed for need ID references and one-line need definitions. ``.json`` files are also checked when they begin with a comment (see jsonc.org). -- ✨ Added TypeScript comment type support for source discovery and analysis. - - TypeScript files can now be processed using ``comment_type = "ts"``. - Source discovery supports both ``.ts`` and ``.tsx`` extensions by default. - - 👌 Replaced ``gitignore-parser`` with ``ignore-python`` for source discovery. This adds native nested ``.gitignore`` support, improves performance, and brings behavioral From 4d8509481f5a11e40de5b88f8e6205b423990c49 Mon Sep 17 00:00:00 2001 From: Arnaud Riess Date: Mon, 22 Jun 2026 16:18:13 +0200 Subject: [PATCH 3/4] =?UTF-8?q?=E2=9C=A8=20Update=20changelog:=20Add=20Typ?= =?UTF-8?q?eScript=20support=20details=20for=20source=20discovery=20and=20?= =?UTF-8?q?analysis?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/source/development/change_log.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/source/development/change_log.rst b/docs/source/development/change_log.rst index 4901b69..cfb8246 100644 --- a/docs/source/development/change_log.rst +++ b/docs/source/development/change_log.rst @@ -6,11 +6,17 @@ Changelog Under development ----------------- +New and Improved +................ + - ✨ Added TypeScript comment type support for source discovery and analysis. TypeScript files can now be processed using ``comment_type = "ts"``. Source discovery supports both ``.ts`` and ``.tsx`` extensions by default. +Fixes +..... + .. _`release:1.3.0`: 1.3.0 From 28e12e1c07e31cc8f58fff3c91beaa77d10e5852 Mon Sep 17 00:00:00 2001 From: Arnaud Riess Date: Mon, 22 Jun 2026 16:28:21 +0200 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=90=9B=20FIX:=20Resolve=20CI=20pre-co?= =?UTF-8?q?mmit=20and=20docs=20build=20failures?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/source/components/configuration.rst | 10 +-- tests/data/discover_fixtures.json | 2 +- tests/test_analyse.py | 99 ++++++++++++------------ 3 files changed, 55 insertions(+), 56 deletions(-) diff --git a/docs/source/components/configuration.rst b/docs/source/components/configuration.rst index cdad9d8..8e6d36d 100644 --- a/docs/source/components/configuration.rst +++ b/docs/source/components/configuration.rst @@ -304,11 +304,11 @@ Specifies the comment syntax style used in the source code files. This determine ``/* */`` (multi-line), ``///`` (XML doc comments) - ``.cs`` - * - TypeScript - - ``"ts"`` - - ``//`` (single-line), - ``/* */`` (multi-line) - - ``.ts``, ``.tsx`` + * - TypeScript + - ``"ts"`` + - ``//`` (single-line), + ``/* */`` (multi-line) + - ``.ts``, ``.tsx`` * - YAML - ``"yaml"`` - ``#`` (single-line) diff --git a/tests/data/discover_fixtures.json b/tests/data/discover_fixtures.json index 738c619..5959cab 100644 --- a/tests/data/discover_fixtures.json +++ b/tests/data/discover_fixtures.json @@ -419,4 +419,4 @@ "src/main.ts" ] } -] \ No newline at end of file +] diff --git a/tests/test_analyse.py b/tests/test_analyse.py index 2973ed6..fe7098a 100644 --- a/tests/test_analyse.py +++ b/tests/test_analyse.py @@ -56,34 +56,34 @@ def test_analyse(src_dir, src_paths, tmp_path, snapshot_marks): @pytest.mark.parametrize( - "src_dir, src_paths, comment_type, oneline_comment_style, result", + "case", [ - ( - TEST_DIR / "data" / "dcdc", - [ + { + "src_dir": TEST_DIR / "data" / "dcdc", + "src_paths": [ TEST_DIR / "data" / "dcdc" / "charge" / "demo_1.cpp", TEST_DIR / "data" / "dcdc" / "charge" / "demo_2.cpp", TEST_DIR / "data" / "dcdc" / "discharge" / "demo_3.cpp", TEST_DIR / "data" / "dcdc" / "supercharge.cpp", ], - "cpp", - ONELINE_COMMENT_STYLE, - { + "comment_type": "cpp", + "oneline_comment_style": ONELINE_COMMENT_STYLE, + "result": { "num_src_files": 4, "num_uncached_files": 4, "num_cached_files": 0, "num_comments": 29, "num_oneline_warnings": 0, }, - ), - ( - TEST_DIR / "data" / "oneline_comment_basic", - [ + }, + { + "src_dir": TEST_DIR / "data" / "oneline_comment_basic", + "src_paths": [ TEST_DIR / "data" / "oneline_comment_basic" / "basic_oneliners.c", ], - "cpp", - ONELINE_COMMENT_STYLE, - { + "comment_type": "cpp", + "oneline_comment_style": ONELINE_COMMENT_STYLE, + "result": { "num_src_files": 1, "num_uncached_files": 1, "num_cached_files": 0, @@ -91,15 +91,15 @@ def test_analyse(src_dir, src_paths, tmp_path, snapshot_marks): "num_oneline_warnings": 0, "warnings_path_exists": True, }, - ), - ( - TEST_DIR / "data" / "oneline_comment_default", - [ + }, + { + "src_dir": TEST_DIR / "data" / "oneline_comment_default", + "src_paths": [ TEST_DIR / "data" / "oneline_comment_default" / "default_oneliners.c", ], - "cpp", - ONELINE_COMMENT_STYLE_DEFAULT, - { + "comment_type": "cpp", + "oneline_comment_style": ONELINE_COMMENT_STYLE_DEFAULT, + "result": { "num_src_files": 1, "num_uncached_files": 1, "num_cached_files": 0, @@ -107,69 +107,68 @@ def test_analyse(src_dir, src_paths, tmp_path, snapshot_marks): "num_oneline_warnings": 1, "warnings_path_exists": True, }, - ), - ( - TEST_DIR / "data" / "rust", - [ + }, + { + "src_dir": TEST_DIR / "data" / "rust", + "src_paths": [ TEST_DIR / "data" / "rust" / "demo.rs", ], - "rust", - ONELINE_COMMENT_STYLE_DEFAULT, - { + "comment_type": "rust", + "oneline_comment_style": ONELINE_COMMENT_STYLE_DEFAULT, + "result": { "num_src_files": 1, "num_uncached_files": 1, "num_cached_files": 0, "num_comments": 6, "num_oneline_warnings": 0, }, - ), - ( - TEST_DIR / "data" / "typescript", - [ + }, + { + "src_dir": TEST_DIR / "data" / "typescript", + "src_paths": [ TEST_DIR / "data" / "typescript" / "demo.ts", ], - "ts", - ONELINE_COMMENT_STYLE_DEFAULT, - { + "comment_type": "ts", + "oneline_comment_style": ONELINE_COMMENT_STYLE_DEFAULT, + "result": { "num_src_files": 1, "num_uncached_files": 1, "num_cached_files": 0, "num_comments": 4, "num_oneline_warnings": 0, }, - ), - ( - TEST_DIR / "data" / "jsonc", - [ + }, + { + "src_dir": TEST_DIR / "data" / "jsonc", + "src_paths": [ TEST_DIR / "data" / "jsonc" / "demo.jsonc", ], - CommentType.jsonc, - ONELINE_COMMENT_STYLE_DEFAULT, - { + "comment_type": CommentType.jsonc, + "oneline_comment_style": ONELINE_COMMENT_STYLE_DEFAULT, + "result": { "num_src_files": 1, "num_uncached_files": 1, "num_cached_files": 0, "num_comments": 4, "num_oneline_warnings": 0, }, - ), + }, ], ) -def test_analyse_oneline_needs( - tmp_path, src_dir, src_paths, comment_type, oneline_comment_style, result -): +def test_analyse_oneline_needs(tmp_path, case): src_analyse_config = SourceAnalyseConfig( - src_files=src_paths, - src_dir=src_dir, + src_files=case["src_paths"], + src_dir=case["src_dir"], get_need_id_refs=False, get_oneline_needs=True, get_rst=False, - oneline_comment_style=oneline_comment_style, - comment_type=comment_type, + oneline_comment_style=case["oneline_comment_style"], + comment_type=case["comment_type"], ) src_analyse = SourceAnalyse(src_analyse_config) src_analyse.run() + result = case["result"] assert len(src_analyse.src_files) == result["num_src_files"] assert len(src_analyse.oneline_warnings) == result["num_oneline_warnings"]