Skip to content

Commit 50e9d0c

Browse files
Rename expected export to decodedValue (#61)
Follows exercism/javascript#792 Follows exercism/exercism#5131 The fixtures have to be updated because analyzers don't support versioning yet.
1 parent 8c1122b commit 50e9d0c

File tree

503 files changed

+2123
-2190
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

503 files changed

+2123
-2190
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 0.6.1
4+
5+
- Update dependencies
6+
- Change `resistor-color-duo` expected export name to `decodedValue`
7+
38
## 0.6.0
49

510
- Fix various `shared` comments which had `generic` instead of `general` in their name.

package.json

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@exercism/javascript-analyzer",
3-
"version": "0.6.0",
3+
"version": "0.6.1",
44
"description": "Exercism analyzer for javascript",
55
"repository": "https://github.com/exercism/javascript-analyzer",
66
"author": "Derk-Jan Karrenbeld <[email protected]>",
@@ -24,25 +24,25 @@
2424
"posttest": "yarn lint"
2525
},
2626
"devDependencies": {
27-
"@babel/core": "^7.6.0",
28-
"@babel/preset-env": "^7.6.0",
29-
"@babel/preset-typescript": "^7.6.0",
30-
"@types/jest": "^24.0.18",
31-
"@types/node": "^12.7.5",
32-
"@types/yargs": "^13.0.2",
33-
"@typescript-eslint/eslint-plugin": "^2.3.0",
27+
"@babel/core": "^7.7.5",
28+
"@babel/preset-env": "^7.7.6",
29+
"@babel/preset-typescript": "^7.7.4",
30+
"@types/jest": "^24.0.23",
31+
"@types/node": "^12.12.17",
32+
"@types/yargs": "^13.0.3",
33+
"@typescript-eslint/eslint-plugin": "^2.11.0",
3434
"babel-jest": "^24.9.0",
35-
"eslint": "^6.4.0",
36-
"eslint-plugin-jest": "^22.17.0",
35+
"eslint": "^6.7.2",
36+
"eslint-plugin-jest": "^23.1.1",
3737
"jest": "^24.9.0"
3838
},
3939
"dependencies": {
40-
"@typescript-eslint/parser": "^2.3.1",
41-
"@typescript-eslint/typescript-estree": "^2.3.1",
40+
"@typescript-eslint/parser": "^2.11.0",
41+
"@typescript-eslint/typescript-estree": "^2.11.0",
4242
"esm": "^3.2.25",
43-
"module-alias": "^2.2.1",
44-
"yargs": "^14.0.0",
45-
"typescript": "^3.6.3"
43+
"module-alias": "^2.2.2",
44+
"yargs": "^15.0.2",
45+
"typescript": "^3.7.3"
4646
},
4747
"_moduleAliases": {
4848
"~src": "dist",

src/analyzers/resistor-color-duo/ResistorColorDuoSolution.ts

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
import { AST_NODE_TYPES, TSESTree } from "@typescript-eslint/typescript-estree";
2-
import { Statement, Node, MemberExpression, CallExpression, ArrowFunctionExpression, FunctionExpression, TemplateLiteral } from "@typescript-eslint/typescript-estree/dist/ts-estree/ts-estree";
3-
2+
import { ArrowFunctionExpression, CallExpression, FunctionExpression, Node, Statement, TemplateLiteral } from "@typescript-eslint/typescript-estree/dist/ts-estree/ts-estree";
43
import { extractExport } from "~src/analyzers/utils/extract_export";
54
import { extractMainBody, MainBody } from "~src/analyzers/utils/extract_main_body";
65
import { extractMainMethod, MainMethod } from "~src/analyzers/utils/extract_main_method";
76
import { parameterName } from "~src/analyzers/utils/extract_parameter";
87
import { findFirst } from "~src/analyzers/utils/find_first";
9-
import { findMemberCall } from "~src/analyzers/utils/find_member_call";
10-
import { isNewExpression } from "~src/analyzers/utils/find_new_expression";
118
import { findTopLevelConstants, ProgramConstant, ProgramConstants } from "~src/analyzers/utils/find_top_level_constants";
129
import { isBinaryExpression } from "~src/analyzers/utils/is_binary_expression";
1310
import { isCallExpression } from "~src/analyzers/utils/is_call_expression";
@@ -27,8 +24,8 @@ type Expression = TSESTree.Expression
2724

2825
type MainExport = ReturnType<typeof extractExport>
2926

30-
const EXPECTED_METHOD = 'value'
31-
const EXPECTED_EXPORT = 'value'
27+
const EXPECTED_METHOD = 'decodedValue'
28+
const EXPECTED_EXPORT = 'decodedValue'
3229
const PROBABLE_CONSTANT = 'COLORS'
3330

3431
export class MissingExpectedCall {
@@ -811,10 +808,10 @@ export class ResistorColorDuoSolution {
811808
}
812809

813810
public get hasInlineExport(): boolean {
814-
// export function value
811+
// export function decodedValue
815812
// => no specififers
816813
//
817-
// export { value }
814+
// export { decodedValue }
818815
// => yes specififers
819816
//
820817
return !this.mainExport[0].specifiers || this.mainExport[0].specifiers.length === 0

src/analyzers/resistor-color-duo/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ in and replace the more cryptic numeric indexers with the named items.
2222
`('javascript.resistor-color-duo.destructuring_in_parameter')
2323

2424
const SIGNATURE_NOT_OPTIMAL = factory`
25-
📕 If you look at the tests, the function \`value\` only receives one
25+
📕 If you look at the tests, the function \`decodedValue\` only receives one
2626
parameter. Nothing more and nothing less.
2727
2828
📕 Remove the additional parameters from your function, as their value will
@@ -173,7 +173,7 @@ export class ResistorColorDuoAnalyzer extends IsolatedAnalyzerImpl {
173173
//
174174
// function colorCode(...) { ... }
175175
//
176-
// export function value([tens, ones]) {
176+
// export function decodedValue([tens, ones]) {
177177
// return colorCode(ones) + colorCode(tens) * 10
178178
// }
179179
//

src/analyzers/utils/extract_main_method.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,12 @@ export function extractMainMethod<T extends string = string>(program: Program, n
105105
node.static
106106
&& node.key.type === AST_NODE_TYPES.Identifier
107107
&& node.key.name === name
108+
&& node.value !== null
108109
) {
109110
switch(node.value.type) {
110111
case AST_NODE_TYPES.ArrowFunctionExpression:
111112
case AST_NODE_TYPES.FunctionExpression:
112-
result = Object.assign(node.value, { id: node.key, parent: node })
113+
result = Object.assign(node.value, { id: node.key, parent: node })
113114
this.break()
114115
break;
115116
}

src/analyzers/utils/type_annotations.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ export function parameterType(parameter: Parameter, fallback: string = 'any'): s
2727
}
2828
}
2929

30-
export function annotateType(typeAnnotation?: TSTypeAnnotation, fallback: string = 'any'): string {
31-
if (typeAnnotation === undefined) {
30+
export function annotateType(typeAnnotation?: TSTypeAnnotation | null, fallback: string = 'any'): string {
31+
if (typeAnnotation === undefined || typeAnnotation === null) {
3232
return fallback
3333
}
3434

test/analyzers/resistor-color-duo/__snapshots__/snapshot.ts.snap

+28-28
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,15 @@ IsolatedAnalyzerOutput {
115115
"message": "Did you know that you can export functions, classes and constants directly
116116
inline?
117117
\`\`\`javascript
118-
export const value = colors => ...;
118+
export const decodedValue = colors => ...;
119119
\`\`\`",
120120
"template": "Did you know that you can export functions, classes and constants directly
121121
inline?
122122
\`\`\`javascript
123123
export %{method.signature}
124124
\`\`\`",
125125
"variables": Object {
126-
"method.signature": "const value = colors => ...;",
126+
"method.signature": "const decodedValue = colors => ...;",
127127
},
128128
},
129129
CommentImpl {
@@ -191,15 +191,15 @@ IsolatedAnalyzerOutput {
191191
"message": "Did you know that you can export functions, classes and constants directly
192192
inline?
193193
\`\`\`javascript
194-
export function value(bands) ...
194+
export function decodedValue(bands) ...
195195
\`\`\`",
196196
"template": "Did you know that you can export functions, classes and constants directly
197197
inline?
198198
\`\`\`javascript
199199
export %{method.signature}
200200
\`\`\`",
201201
"variables": Object {
202-
"method.signature": "function value(bands) ...",
202+
"method.signature": "function decodedValue(bands) ...",
203203
},
204204
},
205205
CommentImpl {
@@ -371,10 +371,10 @@ IsolatedAnalyzerOutput {
371371
"comments": Array [
372372
CommentImpl {
373373
"externalTemplate": "javascript.general.no_method",
374-
"message": "No method called \`value\`. The tests won't pass without it.",
374+
"message": "No method called \`decodedValue\`. The tests won't pass without it.",
375375
"template": "No method called \`%{method.name}\`. The tests won't pass without it.",
376376
"variables": Object {
377-
"method.name": "value",
377+
"method.name": "decodedValue",
378378
},
379379
},
380380
],
@@ -1098,12 +1098,12 @@ IsolatedAnalyzerOutput {
10981098
"comments": Array [
10991099
CommentImpl {
11001100
"externalTemplate": "javascript.resistor-color-duo.signature_not_optimal",
1101-
"message": "📕 If you look at the tests, the function \`value\` only receives one
1101+
"message": "📕 If you look at the tests, the function \`decodedValue\` only receives one
11021102
parameter. Nothing more and nothing less.
11031103

11041104
📕 Remove the additional parameters from your function, as their value will
11051105
always be \`undefined\` or whatever default you've assigned.",
1106-
"template": "📕 If you look at the tests, the function \`value\` only receives one
1106+
"template": "📕 If you look at the tests, the function \`decodedValue\` only receives one
11071107
parameter. Nothing more and nothing less.
11081108

11091109
📕 Remove the additional parameters from your function, as their value will
@@ -1292,12 +1292,12 @@ IsolatedAnalyzerOutput {
12921292
"comments": Array [
12931293
CommentImpl {
12941294
"externalTemplate": "javascript.resistor-color-duo.signature_not_optimal",
1295-
"message": "📕 If you look at the tests, the function \`value\` only receives one
1295+
"message": "📕 If you look at the tests, the function \`decodedValue\` only receives one
12961296
parameter. Nothing more and nothing less.
12971297

12981298
📕 Remove the additional parameters from your function, as their value will
12991299
always be \`undefined\` or whatever default you've assigned.",
1300-
"template": "📕 If you look at the tests, the function \`value\` only receives one
1300+
"template": "📕 If you look at the tests, the function \`decodedValue\` only receives one
13011301
parameter. Nothing more and nothing less.
13021302

13031303
📕 Remove the additional parameters from your function, as their value will
@@ -1330,12 +1330,12 @@ IsolatedAnalyzerOutput {
13301330
"comments": Array [
13311331
CommentImpl {
13321332
"externalTemplate": "javascript.general.no_parameter",
1333-
"message": "Your function \`value\` does not have a parameter.
1333+
"message": "Your function \`decodedValue\` does not have a parameter.
13341334
The tests won't pass without it.",
13351335
"template": "Your function \`%{function.name}\` does not have a parameter.
13361336
The tests won't pass without it.",
13371337
"variables": Object {
1338-
"function.name": "value",
1338+
"function.name": "decodedValue",
13391339
},
13401340
},
13411341
],
@@ -1428,12 +1428,12 @@ IsolatedAnalyzerOutput {
14281428
"comments": Array [
14291429
CommentImpl {
14301430
"externalTemplate": "javascript.resistor-color-duo.signature_not_optimal",
1431-
"message": "📕 If you look at the tests, the function \`value\` only receives one
1431+
"message": "📕 If you look at the tests, the function \`decodedValue\` only receives one
14321432
parameter. Nothing more and nothing less.
14331433

14341434
📕 Remove the additional parameters from your function, as their value will
14351435
always be \`undefined\` or whatever default you've assigned.",
1436-
"template": "📕 If you look at the tests, the function \`value\` only receives one
1436+
"template": "📕 If you look at the tests, the function \`decodedValue\` only receives one
14371437
parameter. Nothing more and nothing less.
14381438

14391439
📕 Remove the additional parameters from your function, as their value will
@@ -1450,10 +1450,10 @@ IsolatedAnalyzerOutput {
14501450
"comments": Array [
14511451
CommentImpl {
14521452
"externalTemplate": "javascript.general.no_method",
1453-
"message": "No method called \`value\`. The tests won't pass without it.",
1453+
"message": "No method called \`decodedValue\`. The tests won't pass without it.",
14541454
"template": "No method called \`%{method.name}\`. The tests won't pass without it.",
14551455
"variables": Object {
1456-
"method.name": "value",
1456+
"method.name": "decodedValue",
14571457
},
14581458
},
14591459
],
@@ -1638,10 +1638,10 @@ IsolatedAnalyzerOutput {
16381638
"comments": Array [
16391639
CommentImpl {
16401640
"externalTemplate": "javascript.general.no_method",
1641-
"message": "No method called \`value\`. The tests won't pass without it.",
1641+
"message": "No method called \`decodedValue\`. The tests won't pass without it.",
16421642
"template": "No method called \`%{method.name}\`. The tests won't pass without it.",
16431643
"variables": Object {
1644-
"method.name": "value",
1644+
"method.name": "decodedValue",
16451645
},
16461646
},
16471647
],
@@ -2510,12 +2510,12 @@ IsolatedAnalyzerOutput {
25102510
"comments": Array [
25112511
CommentImpl {
25122512
"externalTemplate": "javascript.resistor-color-duo.signature_not_optimal",
2513-
"message": "📕 If you look at the tests, the function \`value\` only receives one
2513+
"message": "📕 If you look at the tests, the function \`decodedValue\` only receives one
25142514
parameter. Nothing more and nothing less.
25152515

25162516
📕 Remove the additional parameters from your function, as their value will
25172517
always be \`undefined\` or whatever default you've assigned.",
2518-
"template": "📕 If you look at the tests, the function \`value\` only receives one
2518+
"template": "📕 If you look at the tests, the function \`decodedValue\` only receives one
25192519
parameter. Nothing more and nothing less.
25202520

25212521
📕 Remove the additional parameters from your function, as their value will
@@ -2604,10 +2604,10 @@ IsolatedAnalyzerOutput {
26042604
"comments": Array [
26052605
CommentImpl {
26062606
"externalTemplate": "javascript.general.no_method",
2607-
"message": "No method called \`value\`. The tests won't pass without it.",
2607+
"message": "No method called \`decodedValue\`. The tests won't pass without it.",
26082608
"template": "No method called \`%{method.name}\`. The tests won't pass without it.",
26092609
"variables": Object {
2610-
"method.name": "value",
2610+
"method.name": "decodedValue",
26112611
},
26122612
},
26132613
],
@@ -2932,12 +2932,12 @@ IsolatedAnalyzerOutput {
29322932
"comments": Array [
29332933
CommentImpl {
29342934
"externalTemplate": "javascript.resistor-color-duo.signature_not_optimal",
2935-
"message": "📕 If you look at the tests, the function \`value\` only receives one
2935+
"message": "📕 If you look at the tests, the function \`decodedValue\` only receives one
29362936
parameter. Nothing more and nothing less.
29372937

29382938
📕 Remove the additional parameters from your function, as their value will
29392939
always be \`undefined\` or whatever default you've assigned.",
2940-
"template": "📕 If you look at the tests, the function \`value\` only receives one
2940+
"template": "📕 If you look at the tests, the function \`decodedValue\` only receives one
29412941
parameter. Nothing more and nothing less.
29422942

29432943
📕 Remove the additional parameters from your function, as their value will
@@ -3054,10 +3054,10 @@ IsolatedAnalyzerOutput {
30543054
"comments": Array [
30553055
CommentImpl {
30563056
"externalTemplate": "javascript.general.no_method",
3057-
"message": "No method called \`value\`. The tests won't pass without it.",
3057+
"message": "No method called \`decodedValue\`. The tests won't pass without it.",
30583058
"template": "No method called \`%{method.name}\`. The tests won't pass without it.",
30593059
"variables": Object {
3060-
"method.name": "value",
3060+
"method.name": "decodedValue",
30613061
},
30623062
},
30633063
],
@@ -3530,10 +3530,10 @@ IsolatedAnalyzerOutput {
35303530
"comments": Array [
35313531
CommentImpl {
35323532
"externalTemplate": "javascript.general.no_method",
3533-
"message": "No method called \`value\`. The tests won't pass without it.",
3533+
"message": "No method called \`decodedValue\`. The tests won't pass without it.",
35343534
"template": "No method called \`%{method.name}\`. The tests won't pass without it.",
35353535
"variables": Object {
3536-
"method.name": "value",
3536+
"method.name": "decodedValue",
35373537
},
35383538
},
35393539
],

test/analyzers/resistor-color-duo/smoke.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('When running analysis on resistor-color-duo', () => {
2424
return COLORS.indexOf(color)
2525
}
2626
27-
export function value([tens, ones]) {
27+
export function decodedValue([tens, ones]) {
2828
return colorCode(tens) * 10 + colorCode(ones)
2929
}
3030
`.trim()

test/fixtures/resistor-color-duo/0/resistor-color-duo.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ function digit(color) {
44
return COLORS.indexOf(color);
55
}
66

7-
export function value(colors) {
7+
export function decodedValue(colors) {
88
return digit(colors[0]) * 10 + digit(colors[1]);
9-
}
9+
}

test/fixtures/resistor-color-duo/1/resistor-color-duo.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ const COLORS = [
1313

1414
const colorCode = color => COLORS.indexOf(color);
1515

16-
export const value = colors => new Number(colors.map(colorCode).join(""));
16+
export const decodedValue = colors => new Number(colors.map(colorCode).join(""));
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import { value } from './resistor-color-duo.js';
1+
import { decodedValue } from './resistor-color-duo.js';
22

33
describe('Resistor Colors', () => {
44
test('Brown and black', () => {
5-
expect(value(['brown', 'black'])).toEqual(10);
5+
expect(decodedValue(['brown', 'black'])).toEqual(10);
66
});
77

88
test('Blue and grey', () => {
9-
expect(value(['blue', 'grey'])).toEqual(68);
9+
expect(decodedValue(['blue', 'grey'])).toEqual(68);
1010
});
1111

1212
test('Yellow and violet', () => {
13-
expect(value(['yellow', 'violet'])).toEqual(47);
13+
expect(decodedValue(['yellow', 'violet'])).toEqual(47);
1414
});
1515

1616
test('Orange and orange', () => {
17-
expect(value(['orange', 'orange'])).toEqual(33);
17+
expect(decodedValue(['orange', 'orange'])).toEqual(33);
1818
});
1919
});

0 commit comments

Comments
 (0)