1- import { AST_NODE_TYPES , TSESTree } from "@typescript-eslint/typescript-estree" ;
2-
1+ import { TSESTree } from "@typescript-eslint/typescript-estree" ;
32import { factory } from "~src/comments/comment" ;
4- import { NO_METHOD , NO_NAMED_EXPORT , NO_PARAMETER , BETA_COMMENTARY_PREFIX , UNEXPECTED_PARAMETER } from "~src/comments/shared" ;
3+ import { NO_METHOD , NO_NAMED_EXPORT , NO_PARAMETER , UNEXPECTED_PARAMETER } from "~src/comments/shared" ;
54import { NoExportError } from "~src/errors/NoExportError" ;
65import { NoMethodError } from "~src/errors/NoMethodError" ;
76import { AstParser } from "~src/parsers/AstParser" ;
8-
97import { IsolatedAnalyzerImpl } from "../IsolatedAnalyzerImpl" ;
10- import { ResistorColorSolution , HelperNotOptimal , HelperCallNotFound , MethodNotFound , MissingExpectedCall } from "./ResistorColorSolution" ;
8+ import { ResistorColorSolution } from "./ResistorColorSolution" ;
119
1210const TIP_EXPORT_INLINE = factory < 'method.signature' | 'constant.signature' > `
1311Did you know that you can export functions, classes and constants directly
@@ -21,63 +19,50 @@ export ${'method.signature'}
2119
2220const SIGNATURE_NOT_OPTIMAL = factory `
2321📕 If you look at the tests, the function \`colorCode\` only receives one
24- parameter. Nothing more and nothing less.
25-
26- 📕 Remove the additional parameters from your function, as their value will
27- always be \`undefined\` or whatever default you've assigned.
22+ parameter. Nothing more and nothing less. Suggest that the student
23+ removes the additional parameters from your function, as their value will
24+ always be \`undefined\` or whatever default they've assigned.
2825` ( 'javascript.resistor-color.signature_not_optimal' )
2926
3027const USE_INDEX_OF = factory < 'current' > `
28+ 📕 The analyzer expected \`indexOf\`, instead of \`${ 'current' } \`.
29+
3130💬 Replace \`${ 'current' } \` with a different built-in function, a function
3231which does exactly what is now explicitly programmed in: finding the index
3332of a given value in an \`Array\`.
3433` ( 'javascript.resistor-color.use_index_of' )
3534
35+ const USE_ARRAY_COMPREHENSIONS = factory < 'current' > `
36+ 📕 The analyzer expected \`indexOf\`, instead of \`${ 'current' } \`.
37+
38+ 💬 Replace \`${ 'current' } \` with a single function call that _directly_
39+ finds the index of a given input value.
40+ ` ( 'javascript.resistor-color.use_array_comprehensions' )
41+
3642const USE_IMPLICIT_INCLUDES = factory < 'current' > `
37- 💬 Remove the explicit existence check \`.includes\`. When the color-code
38- is received, there is a special value that is returned if the color is not
39- present. Use that special value instead.
43+ 📕 Using \`includes\` iterates _twice_ over the array. Performance is not
44+ an issue in this exercise, but the logic is unnecessary. **Please note**:
45+ throwing an \`Error\`, when a color does not exist, is perfectly fine and
46+ should not be discouraged.
47+
48+ 💬 Remove the explicit existence check \`.includes\`. When the color
49+ string is converted to a color code (number), there is already a special
50+ value which is returned if the color is not present. Look for and use
51+ that value instead.
4052` ( 'javascript.resistor-color.use_implicit_includes' )
4153
4254const DONT_NORMALISE_INPUTS = factory `
55+ 📕 It's always fine to be defensive about inputs, so that a program will
56+ run correctly under more circumstances. However, arbitary input
57+ normalisation is discouraged on Exercism. Later exercises will have
58+ defined inputs that are denormalised where we'll expect sanitizing and
59+ normalising the input. Keep it simple for now.
60+
4361💬 Remove the call to \`.toLowerCase\`. The tests only provide the inputs
4462in lower case, and the colors should be defined in lower case. There is
4563no need to manually normalise the inputs.
4664` ( 'javascript.resistor-color.dont_normalise_inputs' )
4765
48- const USE_ARRAY_COMPREHENSIONS = factory < 'current' > `
49- 💬 Replace \`${ 'current' } \` with a single function call that _directly_
50- finds the index of a given input value.
51- ` ( 'javascript.resistor-color.use_array_comprehensions' )
52-
53- const ISSUE_OPTIMISE_HELPER = factory < 'method.name' > `
54- ⚡ The helper method \`${ 'method.name' } \` is not optimal. The helper can
55- probably be the same as the solution to \`resistor-color\`. Mentor the student
56- to retrieve their solution and/or optimise their helper.
57- ` ( 'javascript.resistor-color.must_optimise_helper' )
58-
59- const ISSUE_USE_A_HELPER = factory `
60- 📕 Mentor the student to add helper function and DRY-up this solution. The
61- solution to \`resistor-color\` can be used as helper method here. When using an
62- \`Array\` as colors source, in a years time, will the student recall why it's
63- the _index_ in that array? When using an \`Object\`, what does the value mean?
64- Re-using \`colorCode\` explains this in both cases.
65-
66- 💬 Using a helper method is good practice, because it replaces a cryptic "member
67- call" with a named call, that can be documented individually.
68- ` ( 'javascript.resistor-color.must_use_a_helper' )
69-
70- const ISSUE_METHOD_NOT_FOUND = factory < 'method.name' > `
71- ⚡ Ensure the method \`${ 'method/name' } \` exists. It was not found when
72- analysing this solution. If it does not exist, point this out to the student.
73-
74- ` ( 'javascript.resistor-color.must_declare_function' )
75-
76- const ISSUE_EXPECTED_CALL = factory < 'method.name' | 'expected.reason' > `
77- 📕 In order to ${ 'expected.reason' } , expected a \`${ 'method.name' } \` call. If
78- that reasoning applies, mentor the student to add this call.
79- ` ( 'javascript.resistor-color.must_add_missing_call' )
80-
8166type Program = TSESTree . Program
8267
8368const Parser : AstParser = new AstParser ( undefined , 1 )
@@ -171,41 +156,13 @@ export class ResistorColorAnalyzer extends IsolatedAnalyzerImpl {
171156 if ( ! solution . isOptimal ( ) ) {
172157 // continue analyzing
173158 this . logger . log ( '~> solution is not optimal' )
174- this . processLastIssue ( solution , output )
175159 return
176160 }
177161
178162 this . checkForTips ( solution , output )
179163 output . approve ( )
180164 }
181165
182- private processLastIssue ( solution : ResistorColorSolution , output : WritableOutput ) : void | never {
183- const lastIssue = solution . entry . lastIssue
184- if ( ! lastIssue ) {
185- this . logger . log ( '~> no entry issue found' )
186- return
187- }
188-
189- if ( lastIssue instanceof HelperNotOptimal ) {
190- // output.add(BETA_COMMENTARY_PREFIX())
191- output . disapprove ( ISSUE_OPTIMISE_HELPER ( { 'method.name' : lastIssue . helperName } ) )
192- } else if ( lastIssue instanceof HelperCallNotFound ) {
193- // output.add(BETA_COMMENTARY_PREFIX())
194- output . disapprove ( ISSUE_USE_A_HELPER ( ) )
195- } else if ( lastIssue instanceof MethodNotFound ) {
196- // output.add(BETA_COMMENTARY_PREFIX())
197- output . disapprove ( ISSUE_METHOD_NOT_FOUND ( { 'method.name' : lastIssue . methodName } ) )
198- } else if ( lastIssue instanceof MissingExpectedCall ) {
199- // output.add(BETA_COMMENTARY_PREFIX())
200- output . add ( ISSUE_EXPECTED_CALL ( { 'method.name' : lastIssue . methodName , 'expected.reason' : lastIssue . reason } ) )
201-
202- output . disapprove ( )
203- } else {
204- this . logger . error ( 'The analyzer did not handle the issue: ' + JSON . stringify ( lastIssue ) )
205- output . redirect ( )
206- }
207- }
208-
209166 private checkForApprovableSolutions ( solution : ResistorColorSolution , output : WritableOutput ) : void | never {
210167 if ( solution || output ) {
211168 return
0 commit comments