Skip to content

Commit 2779432

Browse files
d3lmNemikolhAriPerkkio
authored
chore(style): minor code style adjustments for improved consistency (#152)
Co-authored-by: Jòan <[email protected]> Co-authored-by: Ari Perkkiö <[email protected]>
1 parent a9e6cea commit 2779432

File tree

13 files changed

+160
-28
lines changed

13 files changed

+160
-28
lines changed

.prettierrc

+9-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,13 @@
55
"tabWidth": 2,
66
"semi": true,
77
"bracketSpacing": true,
8-
"plugins": ["prettier-plugin-astro"]
8+
"plugins": ["prettier-plugin-astro"],
9+
"overrides": [
10+
{
11+
"files": "*.astro",
12+
"options": {
13+
"parser": "astro"
14+
}
15+
}
16+
]
917
}

docs/tutorialkit.dev/src/components/Layout/Head.astro

+16-6
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,25 @@ import Default from '@astrojs/starlight/components/Head.astro';
99
<script is:inline async src="https://www.googletagmanager.com/gtag/js?id=G-64MFE82HG5"></script>
1010

1111
<script is:inline>
12-
// @ts-ignore
12+
/**
13+
* We have all those @ts-ignore because the latest version of @astro/language-server
14+
* type check all scripts even if they are interpreted as JavaScript by the language
15+
* server.
16+
*
17+
* Given this script is kinda considered as external, we should do minimal changes
18+
* to it. Adding a single `@ts-nocheck` didn't work :'(.
19+
*/
20+
21+
// @ts-ignore -- see above
1322
window.dataLayer = window.dataLayer || [];
1423

15-
function gtag() {
16-
// @ts-ignore
17-
dataLayer.push(arguments);
24+
// @ts-ignore -- see above
25+
function gtag(...args) {
26+
// @ts-ignore -- see above
27+
window.dataLayer.push(...args);
1828
}
19-
// @ts-ignore
29+
2030
gtag('js', new Date());
21-
// @ts-ignore
31+
2232
gtag('config', 'G-64MFE82HG5');
2333
</script>

docs/tutorialkit.dev/tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
"jsx": "react-jsx",
99
"jsxImportSource": "react",
1010
"types": ["@types/gtag.js"]
11-
}
11+
},
12+
"include": ["src"]
1213
}

eslint.config.mjs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import blitzPlugin from '@blitz/eslint-plugin';
22
import { getNamingConventionRule, tsFileExtensions } from '@blitz/eslint-plugin/dist/configs/typescript.js';
3+
import eslintPluginAstro from 'eslint-plugin-astro';
34

45
export default [
56
{
67
ignores: [
78
'**/dist',
89
'**/node_modules',
9-
'**/.astro',
10+
'**/.astro/**',
1011

1112
// we ignore our demo templates because they may contain code that is formatted specifically for the demo
1213
'docs/demo/src/templates',
@@ -21,6 +22,7 @@ export default [
2122
},
2223
},
2324
}),
25+
...eslintPluginAstro.configs.recommended,
2426
{
2527
files: ['**/env.d.ts', '**/env-default.d.ts'],
2628
rules: {

extensions/vscode/build.mjs

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as esbuild from 'esbuild';
2-
import fs from 'node:fs';
32
import { execa } from 'execa';
3+
import fs from 'node:fs';
44

55
const production = process.argv.includes('--production');
66
const watch = process.argv.includes('--watch');
@@ -18,7 +18,7 @@ async function main() {
1818
external: ['vscode'],
1919
logLevel: 'silent',
2020
plugins: [
21-
/* add to the end of plugins array */
21+
// add to the end of plugins array
2222
esbuildProblemMatcherPlugin,
2323
],
2424
});
@@ -33,7 +33,7 @@ async function main() {
3333
await ctx.dispose();
3434

3535
if (production) {
36-
// rename name in package json to match extension name on store:
36+
// rename name in package json to match extension name on store
3737
const pkgJSON = JSON.parse(fs.readFileSync('./package.json', { encoding: 'utf8' }));
3838

3939
pkgJSON.name = 'tutorialkit';
@@ -50,14 +50,16 @@ const esbuildProblemMatcherPlugin = {
5050
name: 'esbuild-problem-matcher',
5151
setup(build) {
5252
build.onStart(() => {
53-
console.log('[watch] build started');
53+
console.log('[watch] Build started');
5454
});
55+
5556
build.onEnd((result) => {
5657
result.errors.forEach(({ text, location }) => {
5758
console.error(`✘ [ERROR] ${text}`);
5859
console.error(` ${location.file}:${location.line}:${location.column}:`);
5960
});
60-
console.log('[watch] build finished');
61+
62+
console.log('[watch] Build finished');
6163
});
6264
},
6365
};

extensions/vscode/src/commands/index.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ import { selectTutorial } from './tutorialkit.select-tutorial';
66
import { loadTutorial } from './tutorialkit.load-tutorial';
77
import { initialize } from './tutorialkit.initialize';
88

9-
/**
10-
* No need to use these consts outside of this file:
11-
* – Use `cmd[name].command` instead.
12-
*/
9+
// no need to use these consts outside of this file, use `cmd[name].command` instead
1310
const CMD = {
1411
INITIALIZE: 'tutorialkit.initialize',
1512
SELECT_TUTORIAL: 'tutorialkit.select-tutorial',

extensions/vscode/src/commands/tutorialkit.initialize.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as vscode from 'vscode';
2-
import isTutorialKitWorkspace from '../utils/isTutorialKit';
32
import { cmd } from '.';
3+
import isTutorialKitWorkspace from '../utils/isTutorialKit';
44

55
export async function initialize(toastIfEmpty = false) {
66
const tutorialWorkpaces = (vscode.workspace.workspaceFolders || []).filter(isTutorialKitWorkspace);
@@ -10,6 +10,7 @@ export async function initialize(toastIfEmpty = false) {
1010
vscode.window.showInformationMessage(
1111
'No TutorialKit project found in the current workspace. Make sure there is a "@tutorialkit/astro" dependency or devDependency in your package.json file.',
1212
);
13+
1314
vscode.commands.executeCommand('setContext', 'tutorialkit:tree', false);
1415
}
1516
} else if (tutorialWorkpaces.length === 1) {

extensions/vscode/src/commands/tutorialkit.load-tutorial.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as vscode from 'vscode';
2-
import { LessonsTreeDataProvider, getLessonsTreeDataProvider, setLessonsTreeDataProvider } from '../views/lessonsTree';
32
import { extContext } from '../extension';
3+
import { LessonsTreeDataProvider, getLessonsTreeDataProvider, setLessonsTreeDataProvider } from '../views/lessonsTree';
44

55
export async function loadTutorial(uri: vscode.Uri) {
66
setLessonsTreeDataProvider(new LessonsTreeDataProvider(uri, extContext));

extensions/vscode/src/commands/tutorialkit.select-tutorial.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as vscode from 'vscode';
2-
import isTutorialKitWorkspace from '../utils/isTutorialKit';
32
import { cmd } from '.';
3+
import isTutorialKitWorkspace from '../utils/isTutorialKit';
44

55
export async function selectTutorial() {
66
const tutorialWorkpaces = (vscode.workspace.workspaceFolders || []).filter(isTutorialKitWorkspace);

extensions/vscode/src/utils/isTutorialKit.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import * as vscode from 'vscode';
2-
import * as path from 'path';
31
import * as fs from 'fs';
2+
import * as path from 'path';
3+
import * as vscode from 'vscode';
44

55
/**
6-
* Check if the workspace is a TutorialKit workspace
7-
* by looking for a TutorialKit dependency in the package.json file.
6+
* Check if the workspace is a TutorialKit workspace by looking for a
7+
* TutorialKit dependency in the package.json file.
88
*
99
* @param folder The workspace folder to check.
1010
* @returns True if the workspace is a TutorialKit workspace, false otherwise.
@@ -13,6 +13,7 @@ export default function isTutorialKitWorkspace(folder: vscode.WorkspaceFolder):
1313
const packageJsonPath = path.join(folder.uri.fsPath, 'package.json');
1414
const packageJsonContent = fs.readFileSync(packageJsonPath, 'utf8');
1515
const packageJson = JSON.parse(packageJsonContent);
16+
1617
const tutorialkitDependency =
1718
packageJson.dependencies?.['@tutorialkit/astro'] || packageJson.devDependencies?.['@tutorialkit/astro'];
1819

extensions/vscode/src/views/lessonsTree.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@ let lessonsTreeDataProvider: LessonsTreeDataProvider;
1515
export function getLessonsTreeDataProvider() {
1616
return lessonsTreeDataProvider;
1717
}
18+
1819
export function setLessonsTreeDataProvider(provider: LessonsTreeDataProvider) {
1920
lessonsTreeDataProvider = provider;
2021
}
2122

2223
export class LessonsTreeDataProvider implements vscode.TreeDataProvider<Lesson> {
2324
private _lessons: Lesson[] = [];
25+
private _onDidChangeTreeData: vscode.EventEmitter<Lesson | undefined> = new vscode.EventEmitter<Lesson | undefined>();
26+
readonly onDidChangeTreeData: vscode.Event<Lesson | undefined> = this._onDidChangeTreeData.event;
2427

2528
constructor(
2629
private readonly _workspaceRoot: vscode.Uri,
@@ -59,11 +62,14 @@ export class LessonsTreeDataProvider implements vscode.TreeDataProvider<Lesson>
5962
const metadataFilePath = path.join(filePath, metadataFile);
6063
const metadataFileContent = fs.readFileSync(metadataFilePath, 'utf8');
6164
const parsedContent = grayMatter(metadataFileContent);
65+
6266
lesson.name = parsedContent.data.title;
67+
6368
lesson.metadata = {
6469
_path: metadataFilePath,
6570
...(parsedContent.data as any),
6671
};
72+
6773
lessons.push(lesson);
6874
}
6975
}
@@ -72,9 +78,6 @@ export class LessonsTreeDataProvider implements vscode.TreeDataProvider<Lesson>
7278
return lessons;
7379
}
7480

75-
private _onDidChangeTreeData: vscode.EventEmitter<Lesson | undefined> = new vscode.EventEmitter<Lesson | undefined>();
76-
readonly onDidChangeTreeData: vscode.Event<Lesson | undefined> = this._onDidChangeTreeData.event;
77-
7881
refresh(): void {
7982
this._loadLessons();
8083
this._onDidChangeTreeData.fire(undefined);

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"chalk": "^5.3.0",
2828
"commitlint": "^19.3.0",
2929
"conventional-changelog": "^6.0.0",
30+
"eslint-plugin-astro": "^1.2.3",
3031
"husky": "^9.0.11",
3132
"is-ci": "^3.0.1",
3233
"prettier": "^3.3.2",

0 commit comments

Comments
 (0)