-
-
Notifications
You must be signed in to change notification settings - Fork 13
Fix/axis types #121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Fix/axis types #121
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
82f69ae
docs: add ticks inside example
gka 62fb6e4
fix ts imports
gka 36af02a
update screenshots
gka c5a00a4
fix axis styles
gka 188987c
fix default axis opacity
gka 769dfe9
update screenshots
gka 3ee21ca
screenshots
gka 2e05510
..
gka 825660f
fix more imports
gka 19bee36
add tick classes example
gka 1cbd4d8
fix two more ts imports
gka 9523634
add script for checking js extension in imports (thx copilot)
gka cdb82d0
fix more import declarations
gka 80da62c
replace circular import
gka e0702cd
try again
gka 24938b9
once more
gka 28e1e9a
fix imports
gka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
#!/usr/bin/env node | ||
/* eslint-disable no-console */ | ||
|
||
/** | ||
* This script checks for missing .js extensions in import statements. | ||
* It helps identify issues with ESM imports where TypeScript requires .js extensions. | ||
*/ | ||
|
||
import { readFile, readdir, stat } from 'fs/promises'; | ||
import path from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
|
||
// Convert file:// URLs to paths | ||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = path.dirname(__filename); | ||
|
||
// Regular expressions to match import statements without .js extensions | ||
const regexImportFrom = | ||
/import\s+(?:type\s+)?(?:{[^}]*}|\*\s+as\s+[^;]*|[^;{]*)\s+from\s+['"]([^'"]*)['"]/g; | ||
const regexExportFrom = | ||
/export\s+(?:type\s+)?(?:{[^}]*}|\*\s+as\s+[^;]*)\s+from\s+['"]([^'"]*)['"]/g; | ||
|
||
// Skip node_modules and build directories | ||
const excludedDirs = ['node_modules', 'build', '.svelte-kit', 'dist', '.git', 'examples', 'tests']; | ||
|
||
// Only check certain file types | ||
const includedExtensions = ['.ts', '.js', '.svelte']; | ||
|
||
// Paths that should have .js extensions (relative paths and alias paths) | ||
const shouldHaveJsExtension = (importPath) => { | ||
// Skip Svelte imports | ||
if (importPath.endsWith('.svelte')) return false; | ||
|
||
// Skip npm package imports (those that don't start with . or /) | ||
if ( | ||
!importPath.startsWith('.') && | ||
!importPath.startsWith('/') && | ||
!importPath.startsWith('$lib') | ||
) | ||
return false; | ||
|
||
// Skip imports with extensions already | ||
if (path.extname(importPath)) return false; | ||
|
||
return true; | ||
}; | ||
|
||
async function* walkDirectory(dir) { | ||
const entries = await readdir(dir, { withFileTypes: true }); | ||
|
||
for (const entry of entries) { | ||
const fullPath = path.join(dir, entry.name); | ||
|
||
if (entry.isDirectory()) { | ||
if (!excludedDirs.includes(entry.name)) { | ||
yield* walkDirectory(fullPath); | ||
} | ||
} else if (includedExtensions.includes(path.extname(entry.name))) { | ||
yield fullPath; | ||
} | ||
} | ||
} | ||
|
||
async function checkFile(filePath) { | ||
const content = await readFile(filePath, 'utf8'); | ||
const issues = []; | ||
|
||
// Find all import statements | ||
let match; | ||
|
||
// Check import statements | ||
regexImportFrom.lastIndex = 0; | ||
while ((match = regexImportFrom.exec(content)) !== null) { | ||
const importPath = match[1]; | ||
if (shouldHaveJsExtension(importPath)) { | ||
issues.push({ | ||
line: content.substring(0, match.index).split('\n').length, | ||
importPath, | ||
statement: match[0] | ||
}); | ||
} | ||
} | ||
|
||
// Check export from statements | ||
regexExportFrom.lastIndex = 0; | ||
while ((match = regexExportFrom.exec(content)) !== null) { | ||
const importPath = match[1]; | ||
if (shouldHaveJsExtension(importPath)) { | ||
issues.push({ | ||
line: content.substring(0, match.index).split('\n').length, | ||
importPath, | ||
statement: match[0] | ||
}); | ||
} | ||
} | ||
|
||
return { filePath, issues }; | ||
} | ||
|
||
async function main() { | ||
const rootDir = process.argv[2] || process.cwd(); | ||
console.log(`Checking for missing .js extensions in ${rootDir}...\n`); | ||
|
||
let totalIssues = 0; | ||
let filesWithIssues = 0; | ||
|
||
for await (const filePath of walkDirectory(rootDir)) { | ||
const { issues } = await checkFile(filePath); | ||
|
||
if (issues.length > 0) { | ||
console.log(`\x1b[33m${filePath}\x1b[0m`); | ||
filesWithIssues++; | ||
|
||
for (const issue of issues) { | ||
totalIssues++; | ||
console.log( | ||
` Line ${issue.line}: Missing .js extension in import: ${issue.importPath}` | ||
); | ||
console.log(` ${issue.statement}`); | ||
} | ||
console.log(''); | ||
} | ||
} | ||
|
||
if (totalIssues === 0) { | ||
console.log('\x1b[32mNo missing .js extensions found!\x1b[0m'); | ||
} else { | ||
console.log( | ||
`\x1b[31mFound ${totalIssues} missing .js extensions in ${filesWithIssues} files.\x1b[0m` | ||
); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
main().catch((err) => { | ||
console.error('Error:', err); | ||
process.exit(1); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import type { Scale } from '$lib/classes/Scale.svelte.js'; | ||
import { isDate } from '$lib/helpers/typeChecks'; | ||
import type { PlotScale } from '$lib/types/index.js'; | ||
import { isDate } from '$lib/helpers/typeChecks.js'; | ||
|
||
const DATE_TIME: Intl.DateTimeFormatOptions = { | ||
hour: 'numeric', | ||
|
@@ -32,9 +32,9 @@ const autoFormatMonthYear = (locale: string) => { | |
return (date: Date) => format(date).replace(' ', '\n'); | ||
}; | ||
|
||
export default function autoTimeFormat(x: Scale, plotWidth: number, plotLocale: string) { | ||
export default function autoTimeFormat(x: PlotScale, plotWidth: number, plotLocale: string) { | ||
const daysPer100Px = | ||
((toNumber(x.domain[1]) - toNumber(x.domain[0])) / plotWidth / 864e5) * 100; | ||
((toNumber(x.domain[1] as Date) - toNumber(x.domain[0] as Date)) / plotWidth / 864e5) * 100; | ||
const format = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of using inline Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
daysPer100Px < 1 | ||
? autoFormatDateTime(plotLocale) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The hardcoded font size (
11
) is a magic number; consider making this configurable via a prop or theme token to improve flexibility and maintainability.Copilot uses AI. Check for mistakes.