Skip to content

Commit dc62eba

Browse files
committed
Finally got linting code blocks in markdown files to work
1 parent 29e3198 commit dc62eba

File tree

19 files changed

+1116
-149
lines changed

19 files changed

+1116
-149
lines changed

docs/src/buildtools/3-structure.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ determine the versions of dependencies to use:
2222
import _package from '../../../../package.json' with { type: 'json' };
2323

2424
// extract typescript version
25-
const { dependencies: { typescript: typescriptVersion } } = _package
25+
const { dependencies: { typescript: typescriptVersion } } = _package;
2626
```
2727

2828
Although the resolved module path refers to a path outside of the buildtools folder, during compilation, `esbuild` actually

docs/src/buildtools/5-builders/1-modules.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var globalName = (() => {
3535
draw_connected_2d,
3636
make_point,
3737
// etc...
38-
}
38+
};
3939
})();
4040
```
4141

@@ -59,23 +59,23 @@ By default, `esbuild`'s IIFE output doesn't return its exports:
5959

6060
```js
6161
(function() {
62-
var exports = {}
62+
var exports = {};
6363
exports.add_one = function(x) {
6464
return x + 1;
65-
}
66-
})()
65+
};
66+
})();
6767
```
6868

6969
By specifying a `globalName`, the generated code instead becomes:
7070

7171
```js
7272
var module = (function() {
73-
var exports = {}
73+
var exports = {};
7474
exports.add_one = function(x) {
7575
return x + 1;
76-
}
76+
};
7777
return exports;
78-
})()
78+
})();
7979
```
8080

8181
It is then possible to extract the inner IIFE and use it to retrieve the exports.
@@ -102,26 +102,26 @@ After esbuild bundling, both bundles and tabs are parsed using [`acorn`](https:/
102102

103103
```js
104104
var module = (function() {
105-
var exports = {}
105+
var exports = {};
106106
exports.add_one = function(x) {
107107
return x + 1;
108-
}
108+
};
109109

110110
return exports;
111-
})()
111+
})();
112112
```
113113

114114
The AST is then transformed by the `outputBundleOrTab` function, which produces output that looks like this:
115115

116116
```js
117117
export default require => {
118-
var exports = {}
118+
var exports = {};
119119
exports.add_one = function(x) {
120120
return x + 1;
121-
}
121+
};
122122

123123
return exports;
124-
}
124+
};
125125
```
126126

127127
This is what is finally written to the output folders.

docs/src/buildtools/8-testing.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default defineConfig({
1919
test: {
2020
projects: ['./sub-project/vitest.config.js']
2121
}
22-
})
22+
});
2323
```
2424

2525
For the child configuration:
@@ -35,7 +35,7 @@ export default mergeConfig(
3535
name: 'Child Project'
3636
}
3737
})
38-
)
38+
);
3939
```
4040

4141
The actual configuration that's actually resolved by `vitest` actually looks like this:
@@ -46,7 +46,7 @@ const config = {
4646
name: 'Child Project',
4747
projects: ['./sub-project/vitest.config.js']
4848
}
49-
}
49+
};
5050
```
5151

5252
So if you ran `yarn vitest --config ./sub-project/vitest.config.js`, `vitest` would try to locate another `vitest` project
@@ -125,12 +125,12 @@ const fullViteConfig = {
125125
test: {
126126
name: 'Tests'
127127
}
128-
}
128+
};
129129

130130
// Pass this to startVitest instead
131131
const vitestConfig = {
132132
name: 'Tests'
133-
}
133+
};
134134
```
135135

136136
You should also pass `config: false`. Otherwise, `vitest` will still try to load a `vitest` configuration file
@@ -140,7 +140,7 @@ using its own resolution rules:
140140
startVitest('test', [], {
141141
config: false,
142142
...testOptions
143-
})
143+
});
144144
```
145145

146146
When running tests, you need to actually provide each configuration object as a project:
@@ -149,7 +149,7 @@ When running tests, you need to actually provide each configuration object as a
149149
startVitest('test', [], {
150150
config: false,
151151
projects: [yourTestConfig]
152-
})
152+
});
153153
```
154154

155155
## Browser Mode

docs/src/lib/lintplugin/2-rules.md

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ The rule has a configuration option, which is just an object whose keys represen
1414
```ts
1515
type RuleOptions = {
1616
[source: string]: string | string[]
17-
}
17+
};
1818
```
1919

2020
### Specifying a Single Name
@@ -33,7 +33,7 @@ import * as path from 'path';
3333
// with the option set to { path: 'pathlib' }
3434
import pathlib from 'path';
3535
import * as pathlib from 'path';
36-
import fs from 'fs/promises' // This is ignored because it wasn't specified in the options
36+
import fs from 'fs/promises'; // This is ignored because it wasn't specified in the options
3737
```
3838

3939
### Specifying Multiple Names
@@ -55,7 +55,7 @@ You can of course, enforce naming for more than one import source:
5555
// with option: { path: 'pathlib', 'fs/promises': 'fs' }
5656

5757
import fs from 'fs/promises';
58-
import path from 'pathlib'
58+
import path from 'pathlib';
5959

6060
// both import statements will be validated!
6161
```
@@ -69,14 +69,14 @@ through the main export, but also make each function available in a separate pac
6969

7070
```ts
7171
// Imports from the root package
72-
import _ from 'lodash'
73-
_.memoize(func)
72+
import _ from 'lodash';
73+
_.memoize(func);
7474

75-
import { memoize } from 'lodash'
76-
memoize(func)
75+
import { memoize } from 'lodash';
76+
memoize(func);
7777
// vs importing from a "sub-package"
78-
import memoize 'lodash/memoize'
79-
memoize(func)
78+
import memoize from 'lodash/memoize';
79+
memoize(func);
8080
```
8181

8282
The reason for these "per method imports" is to help bundlers more effectively tree-shake and thus more effectively reduce final bundle size.
@@ -89,45 +89,45 @@ The exception to this is Typescript "type-only" imports, since those automatical
8989

9090
```ts
9191
// Are perfectly ok
92-
import type _ from 'lodash'
93-
import type { memoize } from 'lodash'
92+
import type _ from 'lodash';
93+
import type { memoize } from 'lodash';
9494
```
9595

9696
### Fixes
9797

9898
The rule replaces the original import with different import statements from each of the subpackages:
9999

100100
```ts
101-
import { memoize } from 'lodash'
101+
import { memoize } from 'lodash';
102102
// gets autofixed to
103-
import memoize from 'lodash/memoize'
103+
import memoize from 'lodash/memoize';
104104
```
105105

106106
If you aliased the import, the appropriate alias name will be used:
107107

108108
```ts
109-
import { memoize as func } from 'lodash'
109+
import { memoize as func } from 'lodash';
110110
// gets autofixed to
111-
import func from 'lodash/memoize'
111+
import func from 'lodash/memoize';
112112
```
113113

114114
Multiple imports from the root package get transformed like this:
115115

116116
```ts
117-
import { memoize as func, cloneDeep } from 'lodash'
117+
import { memoize as func, cloneDeep } from 'lodash';
118118
// gets autofixed to
119-
import func from 'lodash/memoize'
120-
import cloneDeep from 'lodash/cloneDeep'
121-
import cloneDeep from 'lodash/cloneDeep'
119+
import func from 'lodash/memoize';
120+
import cloneDeep from 'lodash/cloneDeep';
121+
import cloneDeep from 'lodash/cloneDeep';
122122
```
123123

124124
Type-only imports, when mixed with default imports, also get autofixed:
125125

126126
```ts
127-
import { type memoize as func, cloneDeep } from 'lodash'
127+
import { type memoize as func, cloneDeep } from 'lodash';
128128
// gets autofixed to
129-
import type func from 'lodash/memoize'
130-
import cloneDeep from 'lodash/cloneDeep'
129+
import type func from 'lodash/memoize';
130+
import cloneDeep from 'lodash/cloneDeep';
131131
```
132132

133133
> [!WARNING]
@@ -138,10 +138,12 @@ import cloneDeep from 'lodash/cloneDeep'
138138

139139
The rule should be configured with an array of package names to check:
140140

141-
```ts
142-
rules: {
143-
'@sourceacademy/no-barrel-imports': ['error', ['lodash']]
144-
}
141+
```js
142+
const config = {
143+
rules: {
144+
'@sourceacademy/no-barrel-imports': ['error', ['lodash']]
145+
}
146+
};
145147
```
146148

147149
### ✅ Examples of **correct** code for this rule
@@ -150,8 +152,8 @@ rules: {
150152
// with @sourceacademy/no-barrel-imports: ['error', ['lodash']]
151153

152154
// Lone default or namespace imports are ok
153-
import _ from 'lodash'
154-
import * as _ from 'lodash'
155+
import _ from 'lodash';
156+
import * as _ from 'lodash';
155157

156158
// Type-only imports are okay
157159
import type _ from 'lodash';
@@ -164,7 +166,7 @@ import type { memoize } from 'lodash';
164166
// with @sourceacademy/no-barrel-imports: ['error', ['lodash']]
165167

166168
// Regular Import
167-
import { memoize } from 'lodash'
169+
import { memoize } from 'lodash';
168170

169171
// Default import mixed with type imports
170172
import _, { type memoize } from 'lodash';
@@ -219,7 +221,7 @@ export default {
219221
toSpawn: () => false,
220222
iconName: 'icon',
221223
label: 'tab'
222-
}
224+
};
223225
```
224226

225227
Examples of **correct** code for this rule:
@@ -256,9 +258,8 @@ This rule accepts a configuration array with two elements:
256258
- The second option is the name of the imported helper. This is by default `defineTab`.
257259

258260
✅ Examples of **correct** code using these options:
259-
261+
If the rule was configured with `['error', '@sourceacademy/modules-lib/tabs/utils', 'tabHelper']`:
260262
```tsx
261-
/* eslint @sourceacademy/tab-type: ['error', '@sourceacademy/modules-lib/tabs/utils', 'tabHelper'] */
262263
import { tabHelper } from '@sourceacademy/modules-lib/tabs/utils';
263264

264265
export default tabHelper({

docs/src/modules/1-getting-started/5-faq.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ A `tab` on the other hand is more formally defined as an _optional_ user interfa
3333
An example of an implementation of this is from the `pix_n_flix` module. The implementation can be found [here](https://github.com/source-academy/modules/blob/master/src/bundles/pix_n_flix/index.ts). In the module, a function `init()` is provided to the Source programmer. The specifications of the `pix_n_flix` module requires this `init()` function to be applied as the last statement of the Source program. As a result, the `js-slang` evaluator will return the return value of the `init()` function which is a JavaScript object with the type signature shown below.
3434

3535
```ts
36-
{
36+
interface InitReturnValue {
3737
toReplString: () => string;
3838
init: (video: HTMLVideoElement, canvas: HTMLCanvasElement, _errorLogger: () => void) => {};
3939
}

docs/src/modules/2-bundle/1-overview.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ However, only `make_point` is exported at the bundle's entry point however `crea
7878

7979
```js
8080
// User's Source program
81-
import { make_point } from 'curve' // No Error
82-
import { createDrawFunction } from 'curve' // Will throw an error
81+
import { make_point } from 'curve'; // No Error
82+
import { createDrawFunction } from 'curve'; // Will throw an error
8383
```
8484

8585
::: details An aside about exports

docs/src/modules/2-bundle/4-conventions/1-basic.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function configure_options(option_1: boolean, option_2: boolean = false) {
1313

1414
// or this
1515
function concat_strings(...args: string[]) {
16-
return args.join(',')
16+
return args.join(',');
1717
}
1818

1919
// But default and rest parameters are okay for internal use

docs/src/modules/2-bundle/4-conventions/2-abstractions.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ curve => {
4949
drawnCurves.push(curveDrawn);
5050
}
5151
return curveDrawn;
52-
}
52+
};
5353
```
5454

5555
This exposes implementation details to the cadet and "breaks" the `RenderFunction` abstraction. Thus, there is a need for such objects to be able to override the default `toString`
@@ -79,6 +79,7 @@ but if your circumstances can't support it you can refer to the second method wh
7979
>
8080
> ```ts
8181
> import { show } from 'rune';
82+
>
8283
> display(show);
8384
> ```
8485
>
@@ -127,7 +128,7 @@ Referring back to the `curve` bundle's `RenderFunction`s, the type `RenderFuncti
127128
type RenderFunction = {
128129
(func: Curve): CurveDrawn
129130
is3D: boolean
130-
}
131+
};
131132

132133
// Equivalent to
133134
// type RenderFunction = ((func: Curve) => CurveDraw) & { is3D: boolean }
@@ -183,6 +184,7 @@ We've seen the result of the default `toString` implementation. By providing `to
183184

184185
```js
185186
import { draw_connected } from 'curve';
187+
186188
display(draw_connected(200));
187189

188190
// Produces the output below
@@ -201,8 +203,8 @@ provide compile time validation that the property has been set correctly.
201203
There may be cases where you intend for your abstraction to be "decomposable" by cadets. The `Sound` type is just a wrapper around a `js-slang` pair:
202204

203205
```ts
204-
type Wave = (t: number) => number
205-
type Sound = Pair<Wave, number>
206+
type Wave = (t: number) => number;
207+
type Sound = Pair<Wave, number>;
206208
```
207209

208210
For both of these types, the default `toString` behaviour closely follows their definitions:
@@ -231,7 +233,7 @@ interface TextOptions {
231233
color: string
232234
size: number
233235
}
234-
export function change_text_options(options: TextOptions): void
236+
export function change_text_options(options: TextOptions): void;
235237
```
236238

237239
Alternatively, you could do something like this:
@@ -241,8 +243,8 @@ interface TextOptions {
241243
color: string
242244
size: number
243245
}
244-
export function create_text_options(color: string, size: number): TextOptions
245-
export function change_text_options(options: TextOptions): void
246+
export function create_text_options(color: string, size: number): TextOptions;
247+
export function change_text_options(options: TextOptions): void;
246248

247249
// Used like this:
248250
const options = create_text_options('blue', 20);

0 commit comments

Comments
 (0)