Skip to content

Commit

Permalink
Add prettier (#30)
Browse files Browse the repository at this point in the history
* Add prettier

* Format

* Update for new yargs
  • Loading branch information
SleeplessByte authored Sep 4, 2021
1 parent 6842955 commit f32ea22
Show file tree
Hide file tree
Showing 18 changed files with 2,151 additions and 2,594 deletions.
96 changes: 48 additions & 48 deletions .appends/.github/labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,70 +3,70 @@
# https://github.com/exercism/org-wide-files/blob/main/global-files/.github/labels.yml. #
# ----------------------------------------------------------------------------------------- #

- name: "bug :bug:"
- name: 'bug :bug:'
description: "Something isn't working"
color: "b60205"
color: 'b60205'

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

- name: "dependencies :arrow_up_small:"
description: "Pull requests that update a dependency file"
color: "0366d6"
- name: 'dependencies :arrow_up_small:'
description: 'Pull requests that update a dependency file'
color: '0366d6'

- name: "discussion :speech_balloon:"
description: ""
color: "fbca04"
- name: 'discussion :speech_balloon:'
description: ''
color: 'fbca04'

- name: "do not merge :construction:"
- name: 'do not merge :construction:'
description: "Don't merge until this label is removed"
color: "fbca04"
color: 'fbca04'

- name: "documentation :book:"
description: "Improvements or additions to documentation"
color: "1d76db"
- name: 'documentation :book:'
description: 'Improvements or additions to documentation'
color: '1d76db'

- name: "duplicate :repeat:"
description: "This issue or pull request already exists"
color: "ffffff"
- name: 'duplicate :repeat:'
description: 'This issue or pull request already exists'
color: 'ffffff'

- name: "enhancement :unicorn:"
description: "New feature or request"
color: "a2eeef"
- name: 'enhancement :unicorn:'
description: 'New feature or request'
color: 'a2eeef'

- name: "experimental :microscope:"
description: "Speculative functionality or implementation"
color: "b60205"
- name: 'experimental :microscope:'
description: 'Speculative functionality or implementation'
color: 'b60205'

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

- name: "good first issue"
description: "Good for newcomers"
color: "680a9b"
- name: 'good first issue'
description: 'Good for newcomers'
color: '680a9b'

- name: "help wanted"
description: "Extra attention is needed"
color: "680a9b"
- name: 'help wanted'
description: 'Extra attention is needed'
color: '680a9b'

- name: "invalid"
- name: 'invalid'
description: "This doesn't seem right"
color: "ffffff"
color: 'ffffff'

- name: "question :thinking:"
description: "Further information is requested"
color: "000000"
- name: 'question :thinking:'
description: 'Further information is requested'
color: '000000'

- name: "security :rotating_light:"
description: "Security related issue or change"
color: "b60205"
- name: 'security :rotating_light:'
description: 'Security related issue or change'
color: 'b60205'

- name: "upstream :arrow_up:"
description: ""
color: "FFFFFF"
- name: 'upstream :arrow_up:'
description: ''
color: 'FFFFFF'

- name: "wontfix :no_good_woman:"
description: "This will not be worked on"
color: "ffffff"
- name: 'wontfix :no_good_woman:'
description: 'This will not be worked on'
color: 'ffffff'
2 changes: 0 additions & 2 deletions .github/workflows/format-code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ jobs:
- name: 'Format code'
run: ./bin/format.sh
env:
EXERCISM_PRETTIER_VERSION: '2.2.1'

- name: 'Commit formatted code'
run: |
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/verify-code-formatting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,3 @@ jobs:

- name: 'Verify formatting of all files'
run: ./bin/check-formatting.sh
env:
EXERCISM_PRETTIER_VERSION: '2.2.1'
9 changes: 7 additions & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
/.vscode
/.github/labels.yml
/.github/workflows/sync-labels.yml
/dist
/node_modules
/test/fixtures
/tmp

# These are org-wide files (https://github.com/exercism/org-wide-files/)
/.github/labels.yml
/.github/workflows/sync-labels.yml

/CODE_OF_CONDUCT.md
/LICENSE
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 1.3.0

- Bump dependencies
- Add `prettier`
- Use `prettier` from `package.json` in workflows

## 1.2.0

- Support `.meta/config.json` for representation input
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ yarn install

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

```
```bash
yarn build
```

Expand All @@ -26,7 +26,7 @@ yarn global add @exercism/javascript-representer
```

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
`javascript-representer-remote https://exercism.io/... [<output>] [-flag] [--flags]` to work on a remote solution.
`javascript-representer-remote https://exercism.org/... [<output>] [-flag] [--flags]` to work on a remote solution.

## Usage

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

You can pass the following type of URLs:

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

## Using docker

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

```shell
# Ensure that the version matches the version inside .github/format-code.yml
EXERCISM_PRETTIER_VERSION=2.2.1 bin/format.sh
bin/format.sh
```
24 changes: 24 additions & 0 deletions bin/check-formatting.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
#!/bin/bash

if [ -z "$EXERCISM_PRETTIER_VERSION" ]; then
echo "Pulling prettier version from package.json"
EXERCISM_PRETTIER_VERSION=$(yarn list --pattern prettier | grep -Po '.*\sprettier@\K.*')
fi

if [ -z "$EXERCISM_PRETTIER_VERSION" ]; then
echo "---------------------------------------------------"
echo "This script requires the EXERCISM_PRETTIER_VERSION variable to work."
echo "Please see https://exercism.org/docs/building/markdown/style-guide for guidance."
echo "---------------------------------------------------"
echo "This is what yarn list reports:"
echo "$(yarn list prettier)"
echo ""
echo "This is the version that can be extracted:"
echo "$(yarn list --pattern prettier | grep -Po '.*\sprettier@\K.*')"
echo ""
echo "These files are found in the repo root:"
echo "$(ls -p | grep -v /)"
echo "---------------------------------------------------"
exit 1
else
echo "Running format with prettier@$EXERCISM_PRETTIER_VERSION"
fi

npx "prettier@$EXERCISM_PRETTIER_VERSION" --check "**/*.{js,jsx,ts,tsx,css,sass,scss,html,json,md,yml}"
24 changes: 21 additions & 3 deletions bin/format.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
#!/usr/bin/env bash

if [ -z "$EXERCISM_PRETTIER_VERSION" ]; then
echo "This script requires the EXERCISM_PRETTIER_VERSION variable to work."
echo "Please see https://github.com/exercism/v3/blob/master/docs/maintainers/style-guide.md for guidance."
exit 1
echo "Pulling prettier version from package.json"
EXERCISM_PRETTIER_VERSION=$(yarn list --pattern prettier | grep -Po '.*\sprettier@\K.*')
fi

if [ -z "$EXERCISM_PRETTIER_VERSION" ]; then
echo "---------------------------------------------------"
echo "This script requires the EXERCISM_PRETTIER_VERSION variable to work."
echo "Please see https://exercism.org/docs/building/markdown/style-guide for guidance."
echo "---------------------------------------------------"
echo "This is what yarn list reports:"
echo "$(yarn list prettier)"
echo ""
echo "This is the version that can be extracted:"
echo "$(yarn list --pattern prettier | grep -Po '.*\sprettier@\K.*')"
echo ""
echo "These files are found in the repo root:"
echo "$(ls -p | grep -v /)"
echo "---------------------------------------------------"
exit 1
else
echo "Running format with prettier@$EXERCISM_PRETTIER_VERSION"
fi

npx "prettier@$EXERCISM_PRETTIER_VERSION" --write "**/*.{js,jsx,ts,tsx,css,sass,scss,html,json,md,yml}"
43 changes: 22 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@exercism/javascript-representer",
"version": "1.2.0",
"version": "1.3.0",
"description": "Exercism AST representer for javascript",
"repository": "https://github.com/exercism/javascript-representer",
"author": "Derk-Jan Karrenbeld <[email protected]>",
Expand Down Expand Up @@ -28,31 +28,32 @@
"test:bare": "jest"
},
"devDependencies": {
"@babel/core": "^7.13.15",
"@babel/node": "7.13.13",
"@babel/preset-env": "^7.13.15",
"@babel/preset-typescript": "^7.13.0",
"@babel/core": "^7.15.5",
"@babel/node": "^7.15.4",
"@babel/preset-env": "^7.15.4",
"@babel/preset-typescript": "^7.15.0",
"@tsconfig/recommended": "^1.0.1",
"@types/jest": "^26.0.22",
"@types/node": "^14.14.37",
"@types/yargs": "^16.0.1",
"@typescript-eslint/eslint-plugin": "^4.21.0",
"babel-jest": "^26.6.3",
"eslint": "^7.24.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "^24.3.5",
"jest": "^26.6.3"
"@types/jest": "^27.0.1",
"@types/node": "^16.7.10",
"@types/yargs": "^17.0.2",
"@typescript-eslint/eslint-plugin": "^4.30.0",
"babel-jest": "^27.1.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.24.2",
"eslint-plugin-jest": "^24.4.0",
"jest": "^27.1.0",
"prettier": "^2.3.2"
},
"dependencies": {
"@exercism/static-analysis": "^0.8.1",
"@typescript-eslint/parser": "^4.21.0",
"@typescript-eslint/typescript-estree": "^4.21.0",
"@typescript-eslint/visitor-keys": "^4.21.0",
"@exercism/static-analysis": "^0.10.0",
"@typescript-eslint/parser": "^4.30.0",
"@typescript-eslint/typescript-estree": "^4.30.0",
"@typescript-eslint/visitor-keys": "^4.30.0",
"esm": "^3.2.25",
"module-alias": "^2.2.2",
"typescript": "^4.2.4",
"yargs": "^16.2.0"
"typescript": "^4.4.2",
"yargs": "^17.1.1"
},
"_moduleAliases": {
"~src": "dist",
Expand Down
11 changes: 6 additions & 5 deletions src/output/RepresenterAstOutput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ export class RepresenterAstOutput implements Output {
}
}

function normalizeRepresentation(
representation: Readonly<Program>
): { representation: Program; mapping: { [k: string]: string } } {
function normalizeRepresentation(representation: Readonly<Program>): {
representation: Program
mapping: { [k: string]: string }
} {
const mapping: { [k: string]: string } = {}

simpleTraverse(representation, {
Expand Down Expand Up @@ -61,9 +62,9 @@ function findOrMapIdentifier(
return mapping[name]
}

function inverseMapping(mapping: {
function inverseMapping(mapping: { [k: string]: string }): {
[k: string]: string
}): { [k: string]: string } {
} {
return Object.keys(mapping).reduce((result, original) => {
const mapped = mapping[original]
result[mapped] = original
Expand Down
6 changes: 2 additions & 4 deletions src/output/processor/FileOutput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ export const FileOutput: OutputProcessor = async (
options: FileOutputOptions
): Promise<{ representation: string; mapping: string }> => {
const { representation, mapping } = await previous
const {
representation: outputRepresentation,
mapping: outputMapping,
} = getOutputPath(options)
const { representation: outputRepresentation, mapping: outputMapping } =
getOutputPath(options)

const logger = getProcessLogger()
logger.log(`=> writing representation to ${outputRepresentation}`)
Expand Down
Loading

0 comments on commit f32ea22

Please sign in to comment.