Skip to content

Commit 8aec9ed

Browse files
authored
Merge pull request #21 from Wintus/formatter
formatter
2 parents 09949e7 + 86573ca commit 8aec9ed

14 files changed

+3566
-3517
lines changed

.cline/rules/functional-style-guide.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,45 @@ This guide outlines the preferred functional programming practices for this proj
55
## Core Principles
66

77
1. **Pure Functions Over Classes**
8+
89
- Prefer standalone functions over class methods
910
- Export individual functions rather than object/class collections
1011
- Example: Using `export function fetchAllRevisions()` instead of `WikipediaAPI.getAllRevisions()`
1112

1213
2. **Dependency Injection**
14+
1315
- Pass dependencies explicitly as function parameters
1416
- Avoid direct imports within functions when the dependency can be injected
1517
- Example: `function findOneOccurrence(targetText, fetcher, revisions)` instead of directly using WikipediaAPI
1618

1719
3. **Function Composition**
20+
1821
- Build complex operations from small, reusable functions
1922
- Use function composition to create data processing pipelines
2023
- Example: `const revisions = getPageRevisions(data).map(convert)`
2124

2225
4. **Immutability**
26+
2327
- Treat data as immutable whenever possible
2428
- Create new objects/arrays instead of modifying existing ones
2529
- Use ReadonlyArray<T> type for parameters to signal immutability
2630
- Example: `const shuffled = [...array]; // Shallow copy to avoid modifying the original array`
2731

2832
5. **Type Safety**
33+
2934
- Use explicit TypeScript types and interfaces
3035
- Leverage const assertions and satisfies operators
3136
- Create default constants for complex objects
3237
- Example: `export const defaultSearchResult = {...} as const satisfies SearchResult`
3338

3439
6. **Single Responsibility**
40+
3541
- Each function should do one thing and do it well
3642
- Extract helper functions for reusable logic
3743
- Example: Splitting sampling logic into its own function
3844

3945
7. **Generator Functions**
46+
4047
- Use generator functions for lazy evaluation of sequences
4148
- Example: `function* batches<T>(batchSize, array): Generator<ReadonlyArray<T>>`
4249

.editorconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# top-most EditorConfig file
2+
root = true
3+
4+
# Unix-style newlines with a newline ending every file
5+
[*]
6+
end_of_line = lf
7+
insert_final_newline = true
8+
9+
# Use tab indentation
10+
[*]
11+
indent_style = tab

.prettierrc.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"useTabs": true,
3-
"trailingComma": "es5",
4-
"singleQuote": true
2+
"useTabs": true,
3+
"trailingComma": "es5",
4+
"singleQuote": true
55
}

dev-log-20250302.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,27 @@
33
This file contains a condensed summary of the development process for the Wikipedia Blame tool. For detailed implementation notes, see `implementation-notes.md`.
44

55
## Initial Request
6+
67
- Create a Wikipedia Blame web app to find when specific text was added to Wikipedia articles
78
- Similar functionality to git blame
89
- Support for English and Japanese Wikipedia
910

1011
## Project Planning
12+
1113
- Decided on React with TypeScript and Vite for the frontend
1214
- Planned a minimal SPA without router or complex frameworks
1315
- Designed core algorithm with randomized sampling and exhaustive search fallback
1416
- Structured project with components, services, utilities, and types
1517

1618
## Implementation
19+
1720
- Created core WikipediaAPI service for interacting with Wikipedia API
1821
- Implemented RevisionFinder utility with efficient search algorithm
1922
- Developed React components: SearchForm, LanguageSelector, ResultView
2023
- Added CSS styling with variables for theming
2124

2225
## Technical Highlights
26+
2327
- Used ReadonlyArray for better immutability
2428
- Implemented input trimming on change
2529
- Added language selector with base URLs displayed

eslint.config.js

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
import js from '@eslint/js'
2-
import globals from 'globals'
3-
import reactHooks from 'eslint-plugin-react-hooks'
4-
import reactRefresh from 'eslint-plugin-react-refresh'
5-
import tseslint from 'typescript-eslint'
1+
import js from '@eslint/js';
2+
import globals from 'globals';
3+
import reactHooks from 'eslint-plugin-react-hooks';
4+
import reactRefresh from 'eslint-plugin-react-refresh';
5+
import tseslint from 'typescript-eslint';
66

77
export default tseslint.config(
8-
{ ignores: ['dist'] },
9-
{
10-
extends: [js.configs.recommended, ...tseslint.configs.recommended],
11-
files: ['**/*.{ts,tsx}'],
12-
languageOptions: {
13-
ecmaVersion: 2020,
14-
globals: globals.browser,
15-
},
16-
plugins: {
17-
'react-hooks': reactHooks,
18-
'react-refresh': reactRefresh,
19-
},
20-
rules: {
21-
...reactHooks.configs.recommended.rules,
22-
'react-refresh/only-export-components': [
23-
'warn',
24-
{ allowConstantExport: true },
25-
],
26-
},
27-
},
28-
)
8+
{ ignores: ['dist'] },
9+
{
10+
extends: [js.configs.recommended, ...tseslint.configs.recommended],
11+
files: ['**/*.{ts,tsx}'],
12+
languageOptions: {
13+
ecmaVersion: 2020,
14+
globals: globals.browser,
15+
},
16+
plugins: {
17+
'react-hooks': reactHooks,
18+
'react-refresh': reactRefresh,
19+
},
20+
rules: {
21+
...reactHooks.configs.recommended.rules,
22+
'react-refresh/only-export-components': [
23+
'warn',
24+
{ allowConstantExport: true },
25+
],
26+
},
27+
}
28+
);

implementation-notes.md

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Wikipedia Blame Implementation Notes
22

33
## Search Algorithm Implementation
4+
45
- Randomized sampling approach (10% of revisions or at least 5 revisions) for efficiency
56
- Fallback to exhaustive batch search when needed
67
- Parallel fetching of revisions using Promise.all to improve performance
@@ -9,51 +10,57 @@
910
## Key Components
1011

1112
### WikipediaAPI Service
13+
1214
```typescript
1315
// Core functions for interacting with Wikipedia API
1416
async getRevisionTexts(revIds: ReadonlyArray<number>, lang: WikiLanguage = 'en'): Promise<ReadonlyArray<RevisionResult>>
1517
async getAllRevisions(pageTitle: string, lang: WikiLanguage = 'en'): Promise<ReadonlyArray<number>>
1618
```
1719

1820
### RevisionFinder Utility
21+
1922
```typescript
2023
// Non-destructive Fisher-Yates shuffle
21-
function shuffleArray<T>(array: ReadonlyArray<T>): ReadonlyArray<T>
24+
function shuffleArray<T>(array: ReadonlyArray<T>): ReadonlyArray<T>;
2225

2326
// Main search function with sampling approach
2427
async function findOneOccurrence(
25-
targetText: string,
26-
revList: ReadonlyArray<number>,
27-
lang: WikiLanguage = 'en'
28-
): Promise<number | null>
28+
targetText: string,
29+
revList: ReadonlyArray<number>,
30+
lang: WikiLanguage = 'en'
31+
): Promise<number | null>;
2932

3033
// Fallback exhaustive search
3134
async function exhaustiveSearch(
32-
revList: ReadonlyArray<number>,
33-
targetText: string,
34-
lang: WikiLanguage = 'en'
35-
): Promise<number | null>
35+
revList: ReadonlyArray<number>,
36+
targetText: string,
37+
lang: WikiLanguage = 'en'
38+
): Promise<number | null>;
3639
```
3740

3841
### React Components
42+
3943
- **SearchForm**: Handles user input with trimming on change
4044
- **LanguageSelector**: Toggles between English and Japanese Wikipedia with base URLs displayed
4145
- **ResultView**: Displays search results with links to the specific revision
4246

4347
## Technical Decisions
48+
4449
- Used ReadonlyArray for better immutability throughout the codebase
4550
- Implemented trimming of input strings on change rather than just on submit
4651
- Added language selector with base URLs displayed for clarity (en.wikipedia.org/ja.wikipedia.org)
4752
- Structured the app as a minimal SPA without router or complex frameworks
4853
- Used TypeScript types instead of interfaces for consistency
4954

5055
## Implementation Progress
56+
5157
- Core functionality for finding one text occurrence implemented
5258
- Basic UI with search form and results display
5359
- CSS styling with CSS variables for theming and responsive design
5460
- Error handling for API calls and search process
5561

5662
## Future Work
63+
5764
- Implement tests using real Wikipedia endpoints (with mocking)
5865
- Add functionality to find first/last addition/deletion of text
5966
- Add user selection to search further

index.html

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<!doctype html>
22
<html lang="en">
3-
<head>
4-
<meta charset="UTF-8" />
5-
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
6-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7-
<title>Wikipedia Blame</title>
8-
</head>
9-
<body>
10-
<div id="root"></div>
11-
<script type="module" src="/src/main.tsx"></script>
12-
</body>
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Wikipedia Blame</title>
8+
</head>
9+
<body>
10+
<div id="root"></div>
11+
<script type="module" src="/src/main.tsx"></script>
12+
</body>
1313
</html>

0 commit comments

Comments
 (0)