Skip to content

Commit 9f1993e

Browse files
committed
linting
1 parent ce46a1a commit 9f1993e

File tree

8 files changed

+64
-47
lines changed

8 files changed

+64
-47
lines changed

.prettierignore

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
# Don't need to check Ruby / RBI files
2+
sorbet/
3+
tasks/
4+
15
site/.next
26
site/out
37

4-
# Keep this formatting since it's more concise
58
site/lib/log-generation/sample-data.ts
6-
7-
# Don't format generated files
9+
site/lib/log-generation/log-keys.json
810
site/lib/log-generation/log-types.ts
911
site/public/coverage
1012
site/public/yard

site/app/docs/integrations/page.tsx

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ export default function IntegrationsPage() {
6464
events with detailed information about the job.
6565
</p>
6666

67-
<CodeBlock language="json">{formatLog(logGenerator.generateLog(LogType.ACTIVEJOB))}</CodeBlock>
67+
<CodeBlock language="json">
68+
{formatLog(logGenerator.generateLog(LogType.ACTIVEJOB))}
69+
</CodeBlock>
6870

6971
<h2 className="text-2xl font-bold mt-10 mb-4">Sidekiq Integration</h2>
7072
<p className="text-neutral-600 dark:text-neutral-400 mb-4">
@@ -107,7 +109,9 @@ export default function IntegrationsPage() {
107109
<RubyCodeExample name="lograge_custom_options" />
108110

109111
<div className="mt-4">
110-
<CodeBlock language="json">{formatLog(logGenerator.generateLog(LogType.REQUEST))}</CodeBlock>
112+
<CodeBlock language="json">
113+
{formatLog(logGenerator.generateLog(LogType.REQUEST))}
114+
</CodeBlock>
111115
</div>
112116

113117
<h2 className="text-2xl font-bold mt-10 mb-4">Shrine Integration</h2>
@@ -116,15 +120,19 @@ export default function IntegrationsPage() {
116120
other Shrine operations, including file metadata and operation duration.
117121
</p>
118122

119-
<CodeBlock language="json">{formatLog(logGenerator.generateLog(LogType.SHRINE))}</CodeBlock>
123+
<CodeBlock language="json">
124+
{formatLog(logGenerator.generateLog(LogType.SHRINE))}
125+
</CodeBlock>
120126

121127
<h2 className="text-2xl font-bold mt-10 mb-4">CarrierWave Integration</h2>
122128
<p className="text-neutral-600 dark:text-neutral-400 mb-4">
123129
Similar to the Shrine integration, the CarrierWave integration adds
124130
structured logging for file upload operations.
125131
</p>
126132

127-
<CodeBlock language="json">{formatLog(logGenerator.generateLog(LogType.CARRIERWAVE))}</CodeBlock>
133+
<CodeBlock language="json">
134+
{formatLog(logGenerator.generateLog(LogType.CARRIERWAVE))}
135+
</CodeBlock>
128136

129137
<h2 className="text-2xl font-bold mt-10 mb-4">
130138
ActiveStorage Integration
@@ -135,7 +143,9 @@ export default function IntegrationsPage() {
135143
storage service.
136144
</p>
137145

138-
<CodeBlock language="json">{formatLog(logGenerator.generateLog(LogType.ACTIVESTORAGE))}</CodeBlock>
146+
<CodeBlock language="json">
147+
{formatLog(logGenerator.generateLog(LogType.ACTIVESTORAGE))}
148+
</CodeBlock>
139149

140150
<h2 className="text-2xl font-bold mt-10 mb-4">Rack Error Handler</h2>
141151
<p className="text-neutral-600 dark:text-neutral-400 mb-4">
@@ -157,7 +167,9 @@ export default function IntegrationsPage() {
157167
potential security issues.
158168
</p>
159169

160-
<CodeBlock language="json">{formatLog(logGenerator.generateLog(LogType.SECURITY))}</CodeBlock>
170+
<CodeBlock language="json">
171+
{formatLog(logGenerator.generateLog(LogType.SECURITY))}
172+
</CodeBlock>
161173

162174
<h2 className="text-2xl font-bold mt-10 mb-4">Sorbet Integration</h2>
163175
<p className="text-neutral-600 dark:text-neutral-400 mb-4">
@@ -172,7 +184,7 @@ export default function IntegrationsPage() {
172184
<TabsTrigger value="config">Configuration</TabsTrigger>
173185
<TabsTrigger value="error">Type Error Example</TabsTrigger>
174186
</TabsList>
175-
187+
176188
<TabsContent value="config">
177189
<div className="rounded-lg bg-neutral-100 p-4 dark:bg-neutral-900">
178190
<CodeBlock language="ruby" unwrapped={true}>
@@ -187,7 +199,7 @@ config.integrations.enable_sorbet_error_handlers = true
187199
</CodeBlock>
188200
</div>
189201
</TabsContent>
190-
202+
191203
<TabsContent value="error">
192204
<div className="rounded-lg bg-neutral-100 p-4 dark:bg-neutral-900">
193205
<CodeBlock language="json" unwrapped={true}>

site/components/code-block.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ export function CodeBlock({
7171
{title && (
7272
<div className="font-medium text-sm mb-2 text-gray-700">{title}</div>
7373
)}
74-
<div className="overflow-hidden rounded-lg">
75-
{highlighter}
76-
</div>
74+
<div className="overflow-hidden rounded-lg">{highlighter}</div>
7775
</div>
7876
);
7977
}

site/components/log-scroller.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function LogScroller() {
2828
.replace(/(\w"):/g, '$1: ')
2929
.replace(/({)(?!})/g, '$1 ') // Add space after opening brace only if not followed by closing brace
3030
.replace(/(?<!{)(})/g, ' $1') // Add space before closing brace only if not preceded by opening brace
31-
.replace(/\{\s+\}/g, '{}'); // Remove spaces between empty braces
31+
.replace(/\{\s+\}/g, '{}'); // Remove spaces between empty braces
3232

3333
return jsonStr;
3434
}, []);

site/lib/__tests__/codeExamples.test.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,24 +62,25 @@ describe('Code Examples Integration', () => {
6262
it('should provide list of all example IDs', () => {
6363
const ids = getAllExampleIds();
6464
expect(ids.length).toBeGreaterThan(0);
65-
65+
6666
// A few key examples that should be found
6767
expect(ids).toContain('rails_initializer');
6868
expect(ids).toContain('basic_configuration');
6969
expect(ids).toContain('custom_string_scrubber');
7070
});
71-
71+
7272
it('should preserve indentation in code examples relative to first line', () => {
7373
// Check a real example to see if it's properly unindented
7474
const example = getCodeExample('basic_configuration');
7575
expect(example).not.toBeNull();
76-
76+
7777
// Split the code into lines
7878
const lines = example.code.split('\n');
79-
79+
8080
// This should be true: comment line at first level, code line at first level
8181
// The actual indentation after unindenting should preserve the relative structure
82-
expect(lines[0]).toBe('# Configure LogStruct with a block');
83-
expect(lines[1]).toBe('LogStruct.configure do |config|');
82+
expect(lines[0]).toBe('LogStruct.configure do |config|');
83+
expect(lines[1]).toBe('');
84+
expect(lines[2]).toBe(' # your configuration here');
8485
});
8586
});

site/lib/codeExamples.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,26 @@ const RELOAD_INTERVAL_MS = 1000; // 1 second
2222
function unindentCode(code: string): string {
2323
// Split into lines for processing
2424
const lines = code.split('\n');
25-
25+
2626
// Find non-empty lines to determine minimum indentation
27-
const nonEmptyLines = lines.filter(line => line.trim().length > 0);
27+
const nonEmptyLines = lines.filter((line) => line.trim().length > 0);
2828
if (!nonEmptyLines.length) return code;
29-
29+
3030
// Calculate the minimum indentation across all non-empty lines
31-
const indentSizes = nonEmptyLines.map(line => {
31+
const indentSizes = nonEmptyLines.map((line) => {
3232
const match = line.match(/^(\s*)/);
3333
return match ? match[1].length : 0;
3434
});
35-
35+
3636
const minIndent = Math.min(...indentSizes);
37-
37+
3838
// If no common indentation found, return the original code
3939
if (minIndent === 0) return code;
40-
40+
4141
// Remove the common indentation from each line, but only if the line
4242
// has enough characters to avoid cutting into content
4343
return lines
44-
.map(line => {
44+
.map((line) => {
4545
// Only remove indentation from non-empty lines
4646
if (line.trim().length === 0) return line;
4747
// Only remove up to the amount of leading whitespace
@@ -75,10 +75,10 @@ export function extractCodeExample(content: string, id: string): string | null {
7575

7676
// Extract the code between markers without trimming (leading spaces are important)
7777
const extractedCode = contentAfterStart.slice(0, endMatch.index);
78-
78+
7979
// Remove empty lines at the beginning and end
8080
const trimmedCode = extractedCode.replace(/^\s*\n/, '').replace(/\s*$/, '');
81-
81+
8282
// Unindent the code by removing consistent whitespace from the left
8383
return unindentCode(trimmedCode);
8484
}
@@ -144,11 +144,11 @@ export function loadCodeExamples(): Record<string, CodeExample> {
144144
*/
145145
function ensureExamplesLoaded(): void {
146146
const isDevelopment = process.env.NODE_ENV === 'development';
147-
147+
148148
// In development, reload periodically
149149
if (isDevelopment && Date.now() - lastLoadTime > RELOAD_INTERVAL_MS) {
150150
loadCodeExamples();
151-
}
151+
}
152152
// In production or if not loaded yet, load once
153153
else if (Object.keys(CODE_EXAMPLES).length === 0) {
154154
loadCodeExamples();
@@ -164,7 +164,9 @@ export function getCodeExample(id: string): CodeExample {
164164
ensureExamplesLoaded();
165165
const example = CODE_EXAMPLES[id];
166166
if (!example) {
167-
throw new Error(`Code example not found: "${id}". Make sure this example exists in the examples directory.`);
167+
throw new Error(
168+
`Code example not found: "${id}". Make sure this example exists in the examples directory.`,
169+
);
168170
}
169171
return example;
170172
}

site/lib/log-generation/log-generator.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class LogGenerator extends RandomDataGenerator {
3434
*/
3535
transformLog(log: Partial<Log>): Record<string, any> {
3636
const transformedLog: Record<string, any> = {};
37-
37+
3838
// Process each field in the log
3939
Object.entries(log).forEach(([propertyName, value]) => {
4040
const jsonKey = (logKeysMap as Record<string, string>)[propertyName];
@@ -46,7 +46,7 @@ export class LogGenerator extends RandomDataGenerator {
4646
transformedLog[propertyName] = value;
4747
}
4848
});
49-
49+
5050
return transformedLog;
5151
}
5252

@@ -62,7 +62,7 @@ export class LogGenerator extends RandomDataGenerator {
6262
// Security logs are often warnings or errors
6363
level = Math.random() > 0.3 ? LogLevel.WARN : LogLevel.ERROR;
6464
}
65-
65+
6666
// Create a log with common fields
6767
const log: Partial<Log> = {
6868
timestamp: new Date().toISOString(),
@@ -105,7 +105,7 @@ export class LogGenerator extends RandomDataGenerator {
105105
generateLog(logType: LogType): Record<string, any> {
106106
// Generate a typed log then transform it
107107
const typedLog = this.generateTypedLog(logType);
108-
108+
109109
// Transform property names to JSON keys
110110
return this.transformLog(typedLog);
111111
}

tools/log_types_exporter.rb

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# typed: strict
22
# frozen_string_literal: true
33

4+
# cspell:ignore _tnilable
5+
46
# Load LogStruct type definitions
57
require_relative "../lib/log_struct"
68

@@ -39,31 +41,31 @@ def export
3941
File.write(@output_ts_file, content)
4042

4143
puts "Exported log types to #{@output_ts_file}"
42-
44+
4345
# Export LOG_KEYS mapping to JSON
4446
export_keys_to_json
4547
end
46-
48+
4749
# Export LOG_KEYS mapping to a JSON file
4850
sig { params(output_json_file: T.nilable(String)).void }
4951
def export_keys_to_json(output_json_file = nil)
5052
# Default to the same directory as the TypeScript file
5153
output_json_file ||= File.join(File.dirname(@output_ts_file), "log-keys.json")
52-
54+
5355
puts "Exporting LogStruct key mappings to JSON..."
5456
puts "Output file: #{output_json_file}"
55-
57+
5658
# Create output directory if needed
5759
FileUtils.mkdir_p(File.dirname(output_json_file))
58-
60+
5961
# Convert LOG_KEYS to a format suitable for JSON
6062
# - Convert keys from symbols to strings
6163
# - Convert values from symbols to strings
6264
json_keys = LogStruct::LOG_KEYS.transform_keys(&:to_s).transform_values(&:to_s)
63-
65+
6466
# Write to file with pretty formatting
6567
File.write(output_json_file, JSON.pretty_generate(json_keys))
66-
68+
6769
puts "Exported key mappings to #{output_json_file}"
6870
end
6971

@@ -208,9 +210,9 @@ def extract_type_info(prop_info)
208210
# puts "Extracting type info for: #{type_str}"
209211
# puts "Array key present? #{prop_info.key?(:array)}" if prop_info.key?(:array)
210212
# puts "Array value: #{prop_info[:array]}" if prop_info.key?(:array)
211-
213+
212214
# Check for TypedHash specifically (handles metadata field correctly)
213-
if type_obj.is_a?(T::Types::TypedHash) || type_obj.class.name == "T::Types::TypedHash"
215+
if type_obj.is_a?(T::Types::TypedHash) || type_obj.instance_of?(::T::Types::TypedHash)
214216
return {optional: prop_info[:_tnilable] || false, type: "object"}
215217
end
216218

0 commit comments

Comments
 (0)