Skip to content

Commit

Permalink
Rename expected export to decodedValue (#61)
Browse files Browse the repository at this point in the history
Follows exercism/javascript#792
Follows exercism/exercism#5131

The fixtures have to be updated because analyzers don't support versioning yet.
  • Loading branch information
SleeplessByte authored Dec 13, 2019
1 parent 8c1122b commit 50e9d0c
Show file tree
Hide file tree
Showing 503 changed files with 2,123 additions and 2,190 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 0.6.1

- Update dependencies
- Change `resistor-color-duo` expected export name to `decodedValue`

## 0.6.0

- Fix various `shared` comments which had `generic` instead of `general` in their name.
Expand Down
30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@exercism/javascript-analyzer",
"version": "0.6.0",
"version": "0.6.1",
"description": "Exercism analyzer for javascript",
"repository": "https://github.com/exercism/javascript-analyzer",
"author": "Derk-Jan Karrenbeld <[email protected]>",
Expand All @@ -24,25 +24,25 @@
"posttest": "yarn lint"
},
"devDependencies": {
"@babel/core": "^7.6.0",
"@babel/preset-env": "^7.6.0",
"@babel/preset-typescript": "^7.6.0",
"@types/jest": "^24.0.18",
"@types/node": "^12.7.5",
"@types/yargs": "^13.0.2",
"@typescript-eslint/eslint-plugin": "^2.3.0",
"@babel/core": "^7.7.5",
"@babel/preset-env": "^7.7.6",
"@babel/preset-typescript": "^7.7.4",
"@types/jest": "^24.0.23",
"@types/node": "^12.12.17",
"@types/yargs": "^13.0.3",
"@typescript-eslint/eslint-plugin": "^2.11.0",
"babel-jest": "^24.9.0",
"eslint": "^6.4.0",
"eslint-plugin-jest": "^22.17.0",
"eslint": "^6.7.2",
"eslint-plugin-jest": "^23.1.1",
"jest": "^24.9.0"
},
"dependencies": {
"@typescript-eslint/parser": "^2.3.1",
"@typescript-eslint/typescript-estree": "^2.3.1",
"@typescript-eslint/parser": "^2.11.0",
"@typescript-eslint/typescript-estree": "^2.11.0",
"esm": "^3.2.25",
"module-alias": "^2.2.1",
"yargs": "^14.0.0",
"typescript": "^3.6.3"
"module-alias": "^2.2.2",
"yargs": "^15.0.2",
"typescript": "^3.7.3"
},
"_moduleAliases": {
"~src": "dist",
Expand Down
13 changes: 5 additions & 8 deletions src/analyzers/resistor-color-duo/ResistorColorDuoSolution.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { AST_NODE_TYPES, TSESTree } from "@typescript-eslint/typescript-estree";
import { Statement, Node, MemberExpression, CallExpression, ArrowFunctionExpression, FunctionExpression, TemplateLiteral } from "@typescript-eslint/typescript-estree/dist/ts-estree/ts-estree";

import { ArrowFunctionExpression, CallExpression, FunctionExpression, Node, Statement, TemplateLiteral } from "@typescript-eslint/typescript-estree/dist/ts-estree/ts-estree";
import { extractExport } from "~src/analyzers/utils/extract_export";
import { extractMainBody, MainBody } from "~src/analyzers/utils/extract_main_body";
import { extractMainMethod, MainMethod } from "~src/analyzers/utils/extract_main_method";
import { parameterName } from "~src/analyzers/utils/extract_parameter";
import { findFirst } from "~src/analyzers/utils/find_first";
import { findMemberCall } from "~src/analyzers/utils/find_member_call";
import { isNewExpression } from "~src/analyzers/utils/find_new_expression";
import { findTopLevelConstants, ProgramConstant, ProgramConstants } from "~src/analyzers/utils/find_top_level_constants";
import { isBinaryExpression } from "~src/analyzers/utils/is_binary_expression";
import { isCallExpression } from "~src/analyzers/utils/is_call_expression";
Expand All @@ -27,8 +24,8 @@ type Expression = TSESTree.Expression

type MainExport = ReturnType<typeof extractExport>

const EXPECTED_METHOD = 'value'
const EXPECTED_EXPORT = 'value'
const EXPECTED_METHOD = 'decodedValue'
const EXPECTED_EXPORT = 'decodedValue'
const PROBABLE_CONSTANT = 'COLORS'

export class MissingExpectedCall {
Expand Down Expand Up @@ -811,10 +808,10 @@ export class ResistorColorDuoSolution {
}

public get hasInlineExport(): boolean {
// export function value
// export function decodedValue
// => no specififers
//
// export { value }
// export { decodedValue }
// => yes specififers
//
return !this.mainExport[0].specifiers || this.mainExport[0].specifiers.length === 0
Expand Down
4 changes: 2 additions & 2 deletions src/analyzers/resistor-color-duo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ in and replace the more cryptic numeric indexers with the named items.
`('javascript.resistor-color-duo.destructuring_in_parameter')

const SIGNATURE_NOT_OPTIMAL = factory`
📕 If you look at the tests, the function \`value\` only receives one
📕 If you look at the tests, the function \`decodedValue\` only receives one
parameter. Nothing more and nothing less.
📕 Remove the additional parameters from your function, as their value will
Expand Down Expand Up @@ -173,7 +173,7 @@ export class ResistorColorDuoAnalyzer extends IsolatedAnalyzerImpl {
//
// function colorCode(...) { ... }
//
// export function value([tens, ones]) {
// export function decodedValue([tens, ones]) {
// return colorCode(ones) + colorCode(tens) * 10
// }
//
Expand Down
3 changes: 2 additions & 1 deletion src/analyzers/utils/extract_main_method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,12 @@ export function extractMainMethod<T extends string = string>(program: Program, n
node.static
&& node.key.type === AST_NODE_TYPES.Identifier
&& node.key.name === name
&& node.value !== null
) {
switch(node.value.type) {
case AST_NODE_TYPES.ArrowFunctionExpression:
case AST_NODE_TYPES.FunctionExpression:
result = Object.assign(node.value, { id: node.key, parent: node })
result = Object.assign(node.value, { id: node.key, parent: node })
this.break()
break;
}
Expand Down
4 changes: 2 additions & 2 deletions src/analyzers/utils/type_annotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export function parameterType(parameter: Parameter, fallback: string = 'any'): s
}
}

export function annotateType(typeAnnotation?: TSTypeAnnotation, fallback: string = 'any'): string {
if (typeAnnotation === undefined) {
export function annotateType(typeAnnotation?: TSTypeAnnotation | null, fallback: string = 'any'): string {
if (typeAnnotation === undefined || typeAnnotation === null) {
return fallback
}

Expand Down
56 changes: 28 additions & 28 deletions test/analyzers/resistor-color-duo/__snapshots__/snapshot.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,15 @@ IsolatedAnalyzerOutput {
"message": "Did you know that you can export functions, classes and constants directly
inline?
\`\`\`javascript
export const value = colors => ...;
export const decodedValue = colors => ...;
\`\`\`",
"template": "Did you know that you can export functions, classes and constants directly
inline?
\`\`\`javascript
export %{method.signature}
\`\`\`",
"variables": Object {
"method.signature": "const value = colors => ...;",
"method.signature": "const decodedValue = colors => ...;",
},
},
CommentImpl {
Expand Down Expand Up @@ -191,15 +191,15 @@ IsolatedAnalyzerOutput {
"message": "Did you know that you can export functions, classes and constants directly
inline?
\`\`\`javascript
export function value(bands) ...
export function decodedValue(bands) ...
\`\`\`",
"template": "Did you know that you can export functions, classes and constants directly
inline?
\`\`\`javascript
export %{method.signature}
\`\`\`",
"variables": Object {
"method.signature": "function value(bands) ...",
"method.signature": "function decodedValue(bands) ...",
},
},
CommentImpl {
Expand Down Expand Up @@ -371,10 +371,10 @@ IsolatedAnalyzerOutput {
"comments": Array [
CommentImpl {
"externalTemplate": "javascript.general.no_method",
"message": "No method called \`value\`. The tests won't pass without it.",
"message": "No method called \`decodedValue\`. The tests won't pass without it.",
"template": "No method called \`%{method.name}\`. The tests won't pass without it.",
"variables": Object {
"method.name": "value",
"method.name": "decodedValue",
},
},
],
Expand Down Expand Up @@ -1098,12 +1098,12 @@ IsolatedAnalyzerOutput {
"comments": Array [
CommentImpl {
"externalTemplate": "javascript.resistor-color-duo.signature_not_optimal",
"message": "📕 If you look at the tests, the function \`value\` only receives one
"message": "📕 If you look at the tests, the function \`decodedValue\` only receives one
parameter. Nothing more and nothing less.

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

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

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

📕 Remove the additional parameters from your function, as their value will
Expand Down Expand Up @@ -1330,12 +1330,12 @@ IsolatedAnalyzerOutput {
"comments": Array [
CommentImpl {
"externalTemplate": "javascript.general.no_parameter",
"message": "Your function \`value\` does not have a parameter.
"message": "Your function \`decodedValue\` does not have a parameter.
The tests won't pass without it.",
"template": "Your function \`%{function.name}\` does not have a parameter.
The tests won't pass without it.",
"variables": Object {
"function.name": "value",
"function.name": "decodedValue",
},
},
],
Expand Down Expand Up @@ -1428,12 +1428,12 @@ IsolatedAnalyzerOutput {
"comments": Array [
CommentImpl {
"externalTemplate": "javascript.resistor-color-duo.signature_not_optimal",
"message": "📕 If you look at the tests, the function \`value\` only receives one
"message": "📕 If you look at the tests, the function \`decodedValue\` only receives one
parameter. Nothing more and nothing less.

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

📕 Remove the additional parameters from your function, as their value will
Expand All @@ -1450,10 +1450,10 @@ IsolatedAnalyzerOutput {
"comments": Array [
CommentImpl {
"externalTemplate": "javascript.general.no_method",
"message": "No method called \`value\`. The tests won't pass without it.",
"message": "No method called \`decodedValue\`. The tests won't pass without it.",
"template": "No method called \`%{method.name}\`. The tests won't pass without it.",
"variables": Object {
"method.name": "value",
"method.name": "decodedValue",
},
},
],
Expand Down Expand Up @@ -1638,10 +1638,10 @@ IsolatedAnalyzerOutput {
"comments": Array [
CommentImpl {
"externalTemplate": "javascript.general.no_method",
"message": "No method called \`value\`. The tests won't pass without it.",
"message": "No method called \`decodedValue\`. The tests won't pass without it.",
"template": "No method called \`%{method.name}\`. The tests won't pass without it.",
"variables": Object {
"method.name": "value",
"method.name": "decodedValue",
},
},
],
Expand Down Expand Up @@ -2510,12 +2510,12 @@ IsolatedAnalyzerOutput {
"comments": Array [
CommentImpl {
"externalTemplate": "javascript.resistor-color-duo.signature_not_optimal",
"message": "📕 If you look at the tests, the function \`value\` only receives one
"message": "📕 If you look at the tests, the function \`decodedValue\` only receives one
parameter. Nothing more and nothing less.

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

📕 Remove the additional parameters from your function, as their value will
Expand Down Expand Up @@ -2604,10 +2604,10 @@ IsolatedAnalyzerOutput {
"comments": Array [
CommentImpl {
"externalTemplate": "javascript.general.no_method",
"message": "No method called \`value\`. The tests won't pass without it.",
"message": "No method called \`decodedValue\`. The tests won't pass without it.",
"template": "No method called \`%{method.name}\`. The tests won't pass without it.",
"variables": Object {
"method.name": "value",
"method.name": "decodedValue",
},
},
],
Expand Down Expand Up @@ -2932,12 +2932,12 @@ IsolatedAnalyzerOutput {
"comments": Array [
CommentImpl {
"externalTemplate": "javascript.resistor-color-duo.signature_not_optimal",
"message": "📕 If you look at the tests, the function \`value\` only receives one
"message": "📕 If you look at the tests, the function \`decodedValue\` only receives one
parameter. Nothing more and nothing less.

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

📕 Remove the additional parameters from your function, as their value will
Expand Down Expand Up @@ -3054,10 +3054,10 @@ IsolatedAnalyzerOutput {
"comments": Array [
CommentImpl {
"externalTemplate": "javascript.general.no_method",
"message": "No method called \`value\`. The tests won't pass without it.",
"message": "No method called \`decodedValue\`. The tests won't pass without it.",
"template": "No method called \`%{method.name}\`. The tests won't pass without it.",
"variables": Object {
"method.name": "value",
"method.name": "decodedValue",
},
},
],
Expand Down Expand Up @@ -3530,10 +3530,10 @@ IsolatedAnalyzerOutput {
"comments": Array [
CommentImpl {
"externalTemplate": "javascript.general.no_method",
"message": "No method called \`value\`. The tests won't pass without it.",
"message": "No method called \`decodedValue\`. The tests won't pass without it.",
"template": "No method called \`%{method.name}\`. The tests won't pass without it.",
"variables": Object {
"method.name": "value",
"method.name": "decodedValue",
},
},
],
Expand Down
2 changes: 1 addition & 1 deletion test/analyzers/resistor-color-duo/smoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('When running analysis on resistor-color-duo', () => {
return COLORS.indexOf(color)
}
export function value([tens, ones]) {
export function decodedValue([tens, ones]) {
return colorCode(tens) * 10 + colorCode(ones)
}
`.trim()
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/resistor-color-duo/0/resistor-color-duo.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ function digit(color) {
return COLORS.indexOf(color);
}

export function value(colors) {
export function decodedValue(colors) {
return digit(colors[0]) * 10 + digit(colors[1]);
}
}
2 changes: 1 addition & 1 deletion test/fixtures/resistor-color-duo/1/resistor-color-duo.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ const COLORS = [

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

export const value = colors => new Number(colors.map(colorCode).join(""));
export const decodedValue = colors => new Number(colors.map(colorCode).join(""));
10 changes: 5 additions & 5 deletions test/fixtures/resistor-color-duo/1/resistor-color-duo.spec.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { value } from './resistor-color-duo.js';
import { decodedValue } from './resistor-color-duo.js';

describe('Resistor Colors', () => {
test('Brown and black', () => {
expect(value(['brown', 'black'])).toEqual(10);
expect(decodedValue(['brown', 'black'])).toEqual(10);
});

test('Blue and grey', () => {
expect(value(['blue', 'grey'])).toEqual(68);
expect(decodedValue(['blue', 'grey'])).toEqual(68);
});

test('Yellow and violet', () => {
expect(value(['yellow', 'violet'])).toEqual(47);
expect(decodedValue(['yellow', 'violet'])).toEqual(47);
});

test('Orange and orange', () => {
expect(value(['orange', 'orange'])).toEqual(33);
expect(decodedValue(['orange', 'orange'])).toEqual(33);
});
});
Loading

0 comments on commit 50e9d0c

Please sign in to comment.