Skip to content

Commit 96b360e

Browse files
Switch to templated output by default (#40)
By changing the run flag from templates to noTemplates.
1 parent 42a885f commit 96b360e

14 files changed

Lines changed: 78 additions & 38 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## 0.2.0
4+
5+
- Per https://github.com/exercism/automated-mentoring-support/issues/53,
6+
Merge "approve_as_optimal" and "approve_with_comment" into a single status
7+
"approve", and rename the "disapprove_with_comment" status to "disapprove".
8+
- Switch to template output by default (changing the run flag from templates to
9+
noTemplates).
10+
311
## 0.1.1
412

513
Fixes the build and prepare step of the Docker-based image

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@exercism/javascript-analyzer",
3-
"version": "0.1.1",
3+
"version": "0.2.0",
44
"description": "Exercism analyzer for javascript",
55
"repository": "https://github.com/exercism/javascript-analyzer",
66
"author": "Derk-Jan Karrenbeld <derk-jan+github@karrenbeld.info>",

src/analyzers/gigasecond/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ import { isLiteral } from "../utils/is_literal"
2323
import { NO_METHOD, NO_NAMED_EXPORT, NO_PARAMETER, UNEXPECTED_PARAMETER } from "../../comments/shared";
2424
import { AstParser } from "../../parsers/AstParser";
2525

26+
/**
27+
* The factories here SHOULD be kept in sync with exercism/website-copy. Under
28+
* normal use, they do NOT dictate the actual commentary output of the analyzer,
29+
* as that is provided by the website-copy repo.
30+
*
31+
* https://github.com/exercism/website-copy/tree/master/automated-comments/javascript/gigasecond
32+
*/
33+
2634
const TIP_EXPORT_INLINE = factory<'method-signature' | 'const.name'>`
2735
Did you know that you can export functions, classes and constants directly
2836
inline?

src/analyzers/resistor-color/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ import { AstParser, ParsedSource } from "~src/parsers/AstParser";
1717
import { NoSourceError } from "~src/errors/NoSourceError";
1818
import { ParserError } from "~src/errors/ParserError";
1919

20+
/**
21+
* The factories here SHOULD be kept in sync with exercism/website-copy. Under
22+
* normal use, they do NOT dictate the actual commentary output of the analyzer,
23+
* as that is provided by the website-copy repo.
24+
*
25+
* https://github.com/exercism/website-copy/tree/master/automated-comments/javascript/resistor-color
26+
*/
27+
2028
const TIP_EXPORT_INLINE = factory`
2129
Did you know that you can export functions, classes and constants directly
2230
inline?

src/analyzers/two-fer/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ import { AstParser, ParsedSource } from "~src/parsers/AstParser";
2121
import { NoSourceError } from "~src/errors/NoSourceError";
2222
import { ParserError } from "~src/errors/ParserError";
2323

24+
/**
25+
* The factories here SHOULD be kept in sync with exercism/website-copy. Under
26+
* normal use, they do NOT dictate the actual commentary output of the analyzer,
27+
* as that is provided by the website-copy repo.
28+
*
29+
* https://github.com/exercism/website-copy/tree/master/automated-comments/javascript/two-fer
30+
*/
31+
2432
const OPTIMISE_DEFAULT_VALUE = factory<'parameter'>`
2533
You currently use a conditional to branch in case there is no value passed into
2634
\`twoFer\`. Instead you could set the [default value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Default_parameters)

src/comments/shared.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,40 @@
11
import { factory } from "./comment"
22

3+
/**
4+
* The factories here SHOULD be kept in sync with exercism/website-copy. Under
5+
* normal use, they do NOT dictate the actual commentary output of the analyzer,
6+
* as that is provided by the website-copy repo.
7+
*
8+
* https://github.com/exercism/website-copy/tree/master/automated-comments/javascript/general
9+
*/
10+
311
export const NO_METHOD = factory<'method.name'>`
412
No method called \`${'method.name'}\`. The tests won't pass without it.
5-
`('javascript.generic.no_method')
13+
`('javascript.general.no_method')
614

715
export const NO_NAMED_EXPORT = factory<'export.name'>`
816
No [export](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) called \`${'export.name'}\`.
917
The tests won't pass without it.
1018
1119
Did you forget adding: \`export ${'export.name'}\`?
12-
`('javascript.generic.no_named_export')
20+
`('javascript.general.no_named_export')
1321

1422
export const NO_DEFAULT_EXPORT = factory`
1523
No [default](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/default)
1624
[export](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export).
1725
The tests won't pass without it.
1826
1927
Did you forget adding: \`export default ...\`?
20-
`('javascript.generic.no_default_export')
28+
`('javascript.general.no_default_export')
2129

2230
export const NO_PARAMETER = factory<'function.name'>`
2331
Your function \`${'function.name'}\` does not have a parameter.
2432
The tests won't pass without it.
25-
`('javascript.generic.no_parameter')
33+
`('javascript.general.no_parameter')
2634

2735
export const UNEXPECTED_PARAMETER = factory<'type'>`
2836
Did not find a parameter of type \`${'type'}\`.
29-
`('javascript.generic.unexpected_parameter')
37+
`('javascript.general.unexpected_parameter')
3038

3139
export const UNEXPECTED_SPLAT_ARGS = factory<'splat-arg.name' | 'parameter.type'>`
3240
Instead of using \`...${'splat-arg.name'}: ${'parameter.type'}[]\`, you should
@@ -35,7 +43,7 @@ define a parameter called \`${'splat-arg.name'}\` with the type \`${'parameter.t
3543
[Rest parameters / splat arguments](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters)
3644
are great if you don't know how many values you will receive and it can be an
3745
arbitrary number, but in this case you know how many values you want.
38-
`('javascript.generic.unexpected_splat_args')
46+
`('javascript.general.unexpected_splat_args')
3947

4048
export const PREFER_TEMPLATED_STRINGS = factory`
4149
You're manually building a string using string concatenation. You can use a
@@ -46,7 +54,7 @@ instead and interpolate dynamic values:
4654
"Hello there \${firstName}, I will give you \${calculateInventory()} apples."
4755
\`\`\`
4856
49-
`('typescrypt.generic.prefer_templated_strings')
57+
`('typescrypt.general.prefer_templated_strings')
5058

5159
export const PREFER_STRICT_EQUALITY = factory`
5260
In _JavaScript_, always prefer [strict (identity and non-identity) equality](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators#Identity)
@@ -57,7 +65,7 @@ unless you explicitly want to coerce the type of one of the two operands.
5765
5866
There are definitely cases where you'll want to use non-strict equality, but
5967
that's not the case in this exercise.
60-
`('javascript.generic.prefer_strict_equality')
68+
`('javascript.general.prefer_strict_equality')
6169

6270
export const PREFER_UNPREFIXED_UNDERSCORE_PARAMETERS = factory<'parameter.name'>`
6371
Unlike other languages, \`_parameter\` does not signify a *private* variable.
@@ -76,4 +84,4 @@ Message: "${'error'}"
7684
\`\`\`
7785
${'details'}
7886
\`\`\`
79-
`('javascript.generic.parse_error')
87+
`('javascript.general.parse_error')

src/interface.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ interface ExecutionOptions {
1111
inputDir: string;
1212
/** The exercise slug */
1313
exercise: string;
14-
/** If true, expects website-copy to provide the contents of the templates */
15-
templates: boolean;
14+
/** Unless true, expects website-copy to provide the contents of the templates */
15+
noTemplates: boolean;
1616
}
1717

1818
interface AstParser<T extends object> {

src/output/AnalyzerOutput.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ export class AnalyzerOutput implements Output {
8080
* @param {ExecutionOptions} options
8181
* @returns {Promise<string>}
8282
*/
83-
public toProcessable({ templates }: Pick<ExecutionOptions, 'templates'>): Promise<string> {
83+
public toProcessable({ noTemplates }: Pick<ExecutionOptions, 'noTemplates'>): Promise<string> {
8484
return Promise.resolve(
8585
JSON.stringify({
8686
status: this.status,
87-
comments: this.comments.map(templates ? makeExternalComment : makeIsolatedComment)
87+
comments: this.comments.map(noTemplates ? makeIsolatedComment : makeExternalComment)
8888
})
8989
)
9090
}

src/utils/execution_options.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export class ExecutionOptionsImpl implements ExecutionOptions {
77
public inputDir!: string
88
public exercise!: string
99
public dry!: boolean
10-
public templates!: boolean
10+
public noTemplates!: boolean
1111

1212
constructor(options: ExecutionOptions) {
1313
Object.assign(this, options);
@@ -23,26 +23,26 @@ export class ExecutionOptionsImpl implements ExecutionOptions {
2323
.describe('d', 'Unless given, only outputs warnings and errors')
2424
.describe('c', 'If given, outputs to the console')
2525
.describe('o', 'Path relative to the input dir where the analyzis results are stored')
26-
.describe('templates', 'If given, exports templates instead of messages (feature flag)')
26+
.describe('noTemplates', 'Unless given, exports templates instead of messages (feature flag)')
2727
.describe('dry', 'If given, does not output anything to disk')
28-
.boolean(['d', 'c', 'dry', 'templates'])
28+
.boolean(['d', 'c', 'dry', 'noTemplates'])
2929
.string('o')
3030
.default('d', process.env.NODE_ENV === 'development')
3131
.default('c', process.env.NODE_ENV === 'development')
32-
.default('templates', false)
32+
.default('noTemplates', false)
3333
.default('o', './analysis.json')
3434
.default('dry', false)
3535
.help('h')
3636
.alias('h', 'help')
3737
.argv
3838

39-
const { d, c, o, dry, templates, _ } = args
39+
const { d, c, o, dry, noTemplates, _ } = args
4040
return new ExecutionOptionsImpl({
4141
debug: d,
4242
console: c,
4343
output: o,
4444
dry,
45-
templates,
45+
noTemplates,
4646
exercise: _[0],
4747
inputDir: _[1]
4848
})

test/analyzers/two-fer/__snapshots__/snapshot.ts.snap

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ exports[`When running analysis on two-fer fixtures and expecting it to disapprov
9393
AnalyzerOutput {
9494
"comments": Array [
9595
CommentImpl {
96-
"externalTemplate": "javascript.generic.no_method",
96+
"externalTemplate": "javascript.general.no_method",
9797
"message": "No method called \`twoFer\`. The tests won't pass without it.",
9898
"template": "No method called \`%<method.name>s\`. The tests won't pass without it.",
9999
"variables": Object {
100100
"method.name": "twoFer",
101101
},
102102
},
103103
CommentImpl {
104-
"externalTemplate": "javascript.generic.no_named_export",
104+
"externalTemplate": "javascript.general.no_named_export",
105105
"message": "No [export](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) called \`twoFer\`.
106106
The tests won't pass without it.
107107
@@ -163,7 +163,7 @@ exports[`When running analysis on two-fer fixtures and expecting it to disapprov
163163
AnalyzerOutput {
164164
"comments": Array [
165165
CommentImpl {
166-
"externalTemplate": "javascript.generic.prefer_strict_equality",
166+
"externalTemplate": "javascript.general.prefer_strict_equality",
167167
"message": "In _JavaScript_, always prefer [strict (identity and non-identity) equality](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators#Identity)
168168
such as \`===\` and \`!==\` over the forms that use implicit type coercion,
169169
such as [\`==\`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators#Equality)
@@ -203,7 +203,7 @@ exports[`When running analysis on two-fer fixtures and expecting it to disapprov
203203
AnalyzerOutput {
204204
"comments": Array [
205205
CommentImpl {
206-
"externalTemplate": "javascript.generic.prefer_strict_equality",
206+
"externalTemplate": "javascript.general.prefer_strict_equality",
207207
"message": "In _JavaScript_, always prefer [strict (identity and non-identity) equality](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators#Identity)
208208
such as \`===\` and \`!==\` over the forms that use implicit type coercion,
209209
such as [\`==\`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators#Equality)
@@ -325,7 +325,7 @@ exports[`When running analysis on two-fer fixtures and expecting it to disapprov
325325
AnalyzerOutput {
326326
"comments": Array [
327327
CommentImpl {
328-
"externalTemplate": "javascript.generic.prefer_strict_equality",
328+
"externalTemplate": "javascript.general.prefer_strict_equality",
329329
"message": "In _JavaScript_, always prefer [strict (identity and non-identity) equality](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators#Identity)
330330
such as \`===\` and \`!==\` over the forms that use implicit type coercion,
331331
such as [\`==\`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators#Equality)
@@ -385,15 +385,15 @@ exports[`When running analysis on two-fer fixtures and expecting it to disapprov
385385
AnalyzerOutput {
386386
"comments": Array [
387387
CommentImpl {
388-
"externalTemplate": "javascript.generic.no_method",
388+
"externalTemplate": "javascript.general.no_method",
389389
"message": "No method called \`twoFer\`. The tests won't pass without it.",
390390
"template": "No method called \`%<method.name>s\`. The tests won't pass without it.",
391391
"variables": Object {
392392
"method.name": "twoFer",
393393
},
394394
},
395395
CommentImpl {
396-
"externalTemplate": "javascript.generic.no_named_export",
396+
"externalTemplate": "javascript.general.no_named_export",
397397
"message": "No [export](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) called \`twoFer\`.
398398
The tests won't pass without it.
399399

0 commit comments

Comments
 (0)