Skip to content

Commit f32ea22

Browse files
Add prettier (#30)
* Add prettier * Format * Update for new yargs
1 parent 6842955 commit f32ea22

File tree

18 files changed

+2151
-2594
lines changed

18 files changed

+2151
-2594
lines changed

.appends/.github/labels.yml

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,70 +3,70 @@
33
# https://github.com/exercism/org-wide-files/blob/main/global-files/.github/labels.yml. #
44
# ----------------------------------------------------------------------------------------- #
55

6-
- name: "bug :bug:"
6+
- name: 'bug :bug:'
77
description: "Something isn't working"
8-
color: "b60205"
8+
color: 'b60205'
99

10-
- name: "chore :wrench:"
11-
description: "Meta related task such as build, test, linting, maintainers.json etc."
12-
color: "000000"
10+
- name: 'chore :wrench:'
11+
description: 'Meta related task such as build, test, linting, maintainers.json etc.'
12+
color: '000000'
1313

14-
- name: "dependencies :arrow_up_small:"
15-
description: "Pull requests that update a dependency file"
16-
color: "0366d6"
14+
- name: 'dependencies :arrow_up_small:'
15+
description: 'Pull requests that update a dependency file'
16+
color: '0366d6'
1717

18-
- name: "discussion :speech_balloon:"
19-
description: ""
20-
color: "fbca04"
18+
- name: 'discussion :speech_balloon:'
19+
description: ''
20+
color: 'fbca04'
2121

22-
- name: "do not merge :construction:"
22+
- name: 'do not merge :construction:'
2323
description: "Don't merge until this label is removed"
24-
color: "fbca04"
24+
color: 'fbca04'
2525

26-
- name: "documentation :book:"
27-
description: "Improvements or additions to documentation"
28-
color: "1d76db"
26+
- name: 'documentation :book:'
27+
description: 'Improvements or additions to documentation'
28+
color: '1d76db'
2929

30-
- name: "duplicate :repeat:"
31-
description: "This issue or pull request already exists"
32-
color: "ffffff"
30+
- name: 'duplicate :repeat:'
31+
description: 'This issue or pull request already exists'
32+
color: 'ffffff'
3333

34-
- name: "enhancement :unicorn:"
35-
description: "New feature or request"
36-
color: "a2eeef"
34+
- name: 'enhancement :unicorn:'
35+
description: 'New feature or request'
36+
color: 'a2eeef'
3737

38-
- name: "experimental :microscope:"
39-
description: "Speculative functionality or implementation"
40-
color: "b60205"
38+
- name: 'experimental :microscope:'
39+
description: 'Speculative functionality or implementation'
40+
color: 'b60205'
4141

42-
- name: "first-timers only :baby:"
43-
description: "This issue is specifically for those who are new contributors."
44-
color: "b1db51"
42+
- name: 'first-timers only :baby:'
43+
description: 'This issue is specifically for those who are new contributors.'
44+
color: 'b1db51'
4545

46-
- name: "good first issue"
47-
description: "Good for newcomers"
48-
color: "680a9b"
46+
- name: 'good first issue'
47+
description: 'Good for newcomers'
48+
color: '680a9b'
4949

50-
- name: "help wanted"
51-
description: "Extra attention is needed"
52-
color: "680a9b"
50+
- name: 'help wanted'
51+
description: 'Extra attention is needed'
52+
color: '680a9b'
5353

54-
- name: "invalid"
54+
- name: 'invalid'
5555
description: "This doesn't seem right"
56-
color: "ffffff"
56+
color: 'ffffff'
5757

58-
- name: "question :thinking:"
59-
description: "Further information is requested"
60-
color: "000000"
58+
- name: 'question :thinking:'
59+
description: 'Further information is requested'
60+
color: '000000'
6161

62-
- name: "security :rotating_light:"
63-
description: "Security related issue or change"
64-
color: "b60205"
62+
- name: 'security :rotating_light:'
63+
description: 'Security related issue or change'
64+
color: 'b60205'
6565

66-
- name: "upstream :arrow_up:"
67-
description: ""
68-
color: "FFFFFF"
66+
- name: 'upstream :arrow_up:'
67+
description: ''
68+
color: 'FFFFFF'
6969

70-
- name: "wontfix :no_good_woman:"
71-
description: "This will not be worked on"
72-
color: "ffffff"
70+
- name: 'wontfix :no_good_woman:'
71+
description: 'This will not be worked on'
72+
color: 'ffffff'

.github/workflows/format-code.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ jobs:
6262
6363
- name: 'Format code'
6464
run: ./bin/format.sh
65-
env:
66-
EXERCISM_PRETTIER_VERSION: '2.2.1'
6765

6866
- name: 'Commit formatted code'
6967
run: |

.github/workflows/verify-code-formatting.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,3 @@ jobs:
1414

1515
- name: 'Verify formatting of all files'
1616
run: ./bin/check-formatting.sh
17-
env:
18-
EXERCISM_PRETTIER_VERSION: '2.2.1'

.prettierignore

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
/.vscode
2-
/.github/labels.yml
3-
/.github/workflows/sync-labels.yml
42
/dist
53
/node_modules
64
/test/fixtures
75
/tmp
6+
7+
# These are org-wide files (https://github.com/exercism/org-wide-files/)
8+
/.github/labels.yml
9+
/.github/workflows/sync-labels.yml
10+
11+
/CODE_OF_CONDUCT.md
12+
/LICENSE

CHANGELOG.md

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

3+
## 1.3.0
4+
5+
- Bump dependencies
6+
- Add `prettier`
7+
- Use `prettier` from `package.json` in workflows
8+
39
## 1.2.0
410

511
- Support `.meta/config.json` for representation input

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ yarn install
1313

1414
You'll need at least Node LTS for this to work.
1515

16-
```
16+
```bash
1717
yarn build
1818
```
1919

@@ -26,7 +26,7 @@ yarn global add @exercism/javascript-representer
2626
```
2727

2828
On \*nix systems or enabled shells (wsl, bash, git bash, etc.) you can now use `javascript-representer <slug> <input> [<output>] [-flag] [--flags]` to represent a local file (at `input`), or
29-
`javascript-representer-remote https://exercism.io/... [<output>] [-flag] [--flags]` to work on a remote solution.
29+
`javascript-representer-remote https://exercism.org/... [<output>] [-flag] [--flags]` to work on a remote solution.
3030

3131
## Usage
3232

@@ -83,10 +83,11 @@ There are tools provided to run the representer on remote solutions.
8383

8484
You can pass the following type of URLs:
8585

86-
- Published solutions: `/tracks/javascript/exercises/<slug>/<id>`
87-
- Mentor solutions: `/mentor/solutions/<id>`
88-
- Your solutions: `/my/solutions/<id>`
89-
- Private solutions: `/solutions/<id>`
86+
- ~~Published solutions: `/tracks/javascript/exercises/<slug>/<id>`~~
87+
- ~~Mentor solutions: `/mentor/solutions/<id>`~~
88+
- ~~Your solutions: `/my/solutions/<id>`~~
89+
- ~~Private solutions: `/solutions/<id>`~~
90+
- Constructed urls: `/solutions/<uid>` (use the download button when mentoring)
9091

9192
## Using docker
9293

@@ -119,6 +120,5 @@ The easiest way to satisfy the code-format linter is to add a comment to your PR
119120
Alternatively, run the following command:
120121

121122
```shell
122-
# Ensure that the version matches the version inside .github/format-code.yml
123-
EXERCISM_PRETTIER_VERSION=2.2.1 bin/format.sh
123+
bin/format.sh
124124
```

bin/check-formatting.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
11
#!/bin/bash
22

3+
if [ -z "$EXERCISM_PRETTIER_VERSION" ]; then
4+
echo "Pulling prettier version from package.json"
5+
EXERCISM_PRETTIER_VERSION=$(yarn list --pattern prettier | grep -Po '.*\sprettier@\K.*')
6+
fi
7+
8+
if [ -z "$EXERCISM_PRETTIER_VERSION" ]; then
9+
echo "---------------------------------------------------"
10+
echo "This script requires the EXERCISM_PRETTIER_VERSION variable to work."
11+
echo "Please see https://exercism.org/docs/building/markdown/style-guide for guidance."
12+
echo "---------------------------------------------------"
13+
echo "This is what yarn list reports:"
14+
echo "$(yarn list prettier)"
15+
echo ""
16+
echo "This is the version that can be extracted:"
17+
echo "$(yarn list --pattern prettier | grep -Po '.*\sprettier@\K.*')"
18+
echo ""
19+
echo "These files are found in the repo root:"
20+
echo "$(ls -p | grep -v /)"
21+
echo "---------------------------------------------------"
22+
exit 1
23+
else
24+
echo "Running format with prettier@$EXERCISM_PRETTIER_VERSION"
25+
fi
26+
327
npx "prettier@$EXERCISM_PRETTIER_VERSION" --check "**/*.{js,jsx,ts,tsx,css,sass,scss,html,json,md,yml}"

bin/format.sh

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
11
#!/usr/bin/env bash
22

33
if [ -z "$EXERCISM_PRETTIER_VERSION" ]; then
4-
echo "This script requires the EXERCISM_PRETTIER_VERSION variable to work."
5-
echo "Please see https://github.com/exercism/v3/blob/master/docs/maintainers/style-guide.md for guidance."
6-
exit 1
4+
echo "Pulling prettier version from package.json"
5+
EXERCISM_PRETTIER_VERSION=$(yarn list --pattern prettier | grep -Po '.*\sprettier@\K.*')
6+
fi
7+
8+
if [ -z "$EXERCISM_PRETTIER_VERSION" ]; then
9+
echo "---------------------------------------------------"
10+
echo "This script requires the EXERCISM_PRETTIER_VERSION variable to work."
11+
echo "Please see https://exercism.org/docs/building/markdown/style-guide for guidance."
12+
echo "---------------------------------------------------"
13+
echo "This is what yarn list reports:"
14+
echo "$(yarn list prettier)"
15+
echo ""
16+
echo "This is the version that can be extracted:"
17+
echo "$(yarn list --pattern prettier | grep -Po '.*\sprettier@\K.*')"
18+
echo ""
19+
echo "These files are found in the repo root:"
20+
echo "$(ls -p | grep -v /)"
21+
echo "---------------------------------------------------"
22+
exit 1
23+
else
24+
echo "Running format with prettier@$EXERCISM_PRETTIER_VERSION"
725
fi
826

927
npx "prettier@$EXERCISM_PRETTIER_VERSION" --write "**/*.{js,jsx,ts,tsx,css,sass,scss,html,json,md,yml}"

package.json

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@exercism/javascript-representer",
3-
"version": "1.2.0",
3+
"version": "1.3.0",
44
"description": "Exercism AST representer for javascript",
55
"repository": "https://github.com/exercism/javascript-representer",
66
"author": "Derk-Jan Karrenbeld <[email protected]>",
@@ -28,31 +28,32 @@
2828
"test:bare": "jest"
2929
},
3030
"devDependencies": {
31-
"@babel/core": "^7.13.15",
32-
"@babel/node": "7.13.13",
33-
"@babel/preset-env": "^7.13.15",
34-
"@babel/preset-typescript": "^7.13.0",
31+
"@babel/core": "^7.15.5",
32+
"@babel/node": "^7.15.4",
33+
"@babel/preset-env": "^7.15.4",
34+
"@babel/preset-typescript": "^7.15.0",
3535
"@tsconfig/recommended": "^1.0.1",
36-
"@types/jest": "^26.0.22",
37-
"@types/node": "^14.14.37",
38-
"@types/yargs": "^16.0.1",
39-
"@typescript-eslint/eslint-plugin": "^4.21.0",
40-
"babel-jest": "^26.6.3",
41-
"eslint": "^7.24.0",
42-
"eslint-config-prettier": "^8.1.0",
43-
"eslint-plugin-import": "^2.22.1",
44-
"eslint-plugin-jest": "^24.3.5",
45-
"jest": "^26.6.3"
36+
"@types/jest": "^27.0.1",
37+
"@types/node": "^16.7.10",
38+
"@types/yargs": "^17.0.2",
39+
"@typescript-eslint/eslint-plugin": "^4.30.0",
40+
"babel-jest": "^27.1.0",
41+
"eslint": "^7.32.0",
42+
"eslint-config-prettier": "^8.3.0",
43+
"eslint-plugin-import": "^2.24.2",
44+
"eslint-plugin-jest": "^24.4.0",
45+
"jest": "^27.1.0",
46+
"prettier": "^2.3.2"
4647
},
4748
"dependencies": {
48-
"@exercism/static-analysis": "^0.8.1",
49-
"@typescript-eslint/parser": "^4.21.0",
50-
"@typescript-eslint/typescript-estree": "^4.21.0",
51-
"@typescript-eslint/visitor-keys": "^4.21.0",
49+
"@exercism/static-analysis": "^0.10.0",
50+
"@typescript-eslint/parser": "^4.30.0",
51+
"@typescript-eslint/typescript-estree": "^4.30.0",
52+
"@typescript-eslint/visitor-keys": "^4.30.0",
5253
"esm": "^3.2.25",
5354
"module-alias": "^2.2.2",
54-
"typescript": "^4.2.4",
55-
"yargs": "^16.2.0"
55+
"typescript": "^4.4.2",
56+
"yargs": "^17.1.1"
5657
},
5758
"_moduleAliases": {
5859
"~src": "dist",

src/output/RepresenterAstOutput.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ export class RepresenterAstOutput implements Output {
2828
}
2929
}
3030

31-
function normalizeRepresentation(
32-
representation: Readonly<Program>
33-
): { representation: Program; mapping: { [k: string]: string } } {
31+
function normalizeRepresentation(representation: Readonly<Program>): {
32+
representation: Program
33+
mapping: { [k: string]: string }
34+
} {
3435
const mapping: { [k: string]: string } = {}
3536

3637
simpleTraverse(representation, {
@@ -61,9 +62,9 @@ function findOrMapIdentifier(
6162
return mapping[name]
6263
}
6364

64-
function inverseMapping(mapping: {
65+
function inverseMapping(mapping: { [k: string]: string }): {
6566
[k: string]: string
66-
}): { [k: string]: string } {
67+
} {
6768
return Object.keys(mapping).reduce((result, original) => {
6869
const mapped = mapping[original]
6970
result[mapped] = original

0 commit comments

Comments
 (0)