Skip to content

Commit 41cb984

Browse files
iHiDdem4ron
andauthored
Add unused properties (exercism#7848)
* Add unused properties * Update configs * Remove console log --------- Co-authored-by: dem4ron <[email protected]>
1 parent 525c804 commit 41cb984

File tree

17 files changed

+76
-44
lines changed

17 files changed

+76
-44
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import postcss from 'postcss'
2+
import postcssNested from 'postcss-nested'
3+
4+
export async function illegalPropertiesUsed(
5+
css: string,
6+
allowed: string[]
7+
): Promise<string | null> {
8+
const usedProps = new Set<string>()
9+
10+
const result = await postcss([postcssNested]).process(css, {
11+
from: undefined,
12+
})
13+
14+
result.root.walkDecls((decl) => {
15+
usedProps.add(decl.prop)
16+
})
17+
18+
for (const used of usedProps) {
19+
if (!allowed.includes(used)) {
20+
return used
21+
}
22+
}
23+
24+
return null
25+
}

app/javascript/components/bootcamp/CSSExercisePage/checks/runChecks.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export type ChecksResult = {
1111

1212
export type Check = {
1313
function: string
14-
matcher: 'toBeTrue' | 'toBeFalse'
14+
matcher: 'toBeTrue' | 'toBeFalse' | 'toBeUndefined'
1515
errorHtml: string
1616
}
1717

@@ -21,6 +21,9 @@ export function evaluateMatch(result: boolean, matcher: string): boolean {
2121
return result === true
2222
case 'toBeFalse':
2323
return result === false
24+
case 'toBeUndefined':
25+
return result === undefined || result === null
26+
2427
default:
2528
throw new Error(`Unimplemented matcher: ${matcher}`)
2629
}
@@ -63,7 +66,9 @@ export async function runChecks(
6366
return {
6467
result,
6568
passes,
66-
error_html: passes ? null : check.errorHtml,
69+
error_html: passes
70+
? null
71+
: check.errorHtml.replaceAll('%result%', result),
6772
}
6873
} catch (error: any) {
6974
return {

app/javascript/components/bootcamp/CSSExercisePage/checks/runCssChecks.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import {
44
} from './css/elementHasProperty'
55
import { onlyPropertyGroupsUsed } from './css/onlyPropertyGroupsUsed'
66
import { onlyPropertiesUsed } from './css/onlyPropertiesUsed'
7+
import { illegalPropertiesUsed } from './css/illegalPropertiesUsed'
78
import { Check, ChecksResult, runChecks } from './runChecks'
89

910
const cssCheckFunctions: Record<string, Function> = {
1011
elementHasProperty,
1112
elementHasPropertyValue,
1213
onlyPropertyGroupsUsed,
1314
onlyPropertiesUsed,
15+
illegalPropertiesUsed,
1416
}
1517

1618
export async function runCssChecks(

bootcamp_content/projects/flexy-flags/exercises/flexy-armenia/config.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
},
1010
"checks": [
1111
{
12-
"function": "onlyPropertiesUsed(['background','display','flex-direction','flex-grow'])",
13-
"matcher": "toBeTrue",
14-
"errorHtml": "You used a CSS property that is not allowed for this exercise."
12+
"function": "illegalPropertiesUsed(['background','display','flex-direction','flex-grow'])",
13+
"matcher": "toBeUndefined",
14+
"errorHtml": "You used a CSS property that is not allowed for this exercise (%result%)."
1515
}
1616
]
1717
}

bootcamp_content/projects/flexy-flags/exercises/flexy-bangladesh/config.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
},
1010
"checks": [
1111
{
12-
"function": "onlyPropertiesUsed(['background','border-radius','display','justify-content','align-items','flex-basis','flex-grow','aspect-ratio'])",
13-
"matcher": "toBeTrue",
14-
"errorHtml": "You used a CSS property that is not allowed for this exercise."
12+
"function": "illegalPropertiesUsed(['background','border-radius','display','justify-content','align-items','flex-basis','flex-grow','aspect-ratio'])",
13+
"matcher": "toBeUndefined",
14+
"errorHtml": "You used a CSS property that is not allowed for this exercise (%result%)."
1515
}
1616
]
1717
}

bootcamp_content/projects/flexy-flags/exercises/flexy-benin/config.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
},
1010
"checks": [
1111
{
12-
"function": "onlyPropertiesUsed(['background','display','flex-basis','flex-direction','flex-grow'])",
13-
"matcher": "toBeTrue",
14-
"errorHtml": "You used a CSS property that is not allowed for this exercise."
12+
"function": "illegalPropertiesUsed(['background','display','flex-basis','flex-direction','flex-grow'])",
13+
"matcher": "toBeUndefined",
14+
"errorHtml": "You used a CSS property that is not allowed for this exercise (%result%)."
1515
}
1616
]
1717
}

bootcamp_content/projects/flexy-flags/exercises/flexy-botswana/config.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
],
1717
"checks": [
1818
{
19-
"function": "onlyPropertiesUsed(['background','display','flex-basis','flex-direction','flex-grow','gap'])",
20-
"matcher": "toBeTrue",
21-
"errorHtml": "You used a CSS property that is not allowed for this exercise."
19+
"function": "illegalPropertiesUsed(['background','display','flex-basis','flex-direction','flex-grow','gap'])",
20+
"matcher": "toBeUndefined",
21+
"errorHtml": "You used a CSS property that is not allowed for this exercise (%result%)."
2222
}
2323
]
2424
}

bootcamp_content/projects/flexy-flags/exercises/flexy-cameroon/config.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
},
1010
"checks": [
1111
{
12-
"function": "onlyPropertiesUsed(['background','display','flex-basis','flex-grow','justify-content','align-items','width'])",
13-
"matcher": "toBeTrue",
14-
"errorHtml": "You used a CSS property that is not allowed for this exercise."
12+
"function": "illegalPropertiesUsed(['background','display','flex-basis','flex-grow','justify-content','align-items','width'])",
13+
"matcher": "toBeUndefined",
14+
"errorHtml": "You used a CSS property that is not allowed for this exercise (%result%)."
1515
}
1616
]
1717
}

bootcamp_content/projects/flexy-flags/exercises/flexy-denmark/config.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
},
1010
"checks": [
1111
{
12-
"function": "onlyPropertiesUsed(['background','display','flex-basis','flex-wrap','flex-grow','gap'])",
13-
"matcher": "toBeTrue",
14-
"errorHtml": "You used a CSS property that is not allowed for this exercise."
12+
"function": "illegalPropertiesUsed(['background','display','flex-basis','flex-wrap','flex-grow','gap'])",
13+
"matcher": "toBeUndefined",
14+
"errorHtml": "You used a CSS property that is not allowed for this exercise (%result%)."
1515
}
1616
]
1717
}

bootcamp_content/projects/flexy-flags/exercises/flexy-guinea/config.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
},
1010
"checks": [
1111
{
12-
"function": "onlyPropertiesUsed(['background','display','flex-direction','flex-grow'])",
13-
"matcher": "toBeTrue",
14-
"errorHtml": "You used a CSS property that is not allowed for this exercise."
12+
"function": "illegalPropertiesUsed(['background','display','flex-direction','flex-grow'])",
13+
"matcher": "toBeUndefined",
14+
"errorHtml": "You used a CSS property that is not allowed for this exercise (%result%)."
1515
}
1616
]
1717
}

0 commit comments

Comments
 (0)