Skip to content
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.

Commit

Permalink
Add linter and code formatter (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjohnsonpint authored Jan 19, 2024
1 parent a058f5b commit b7581ba
Show file tree
Hide file tree
Showing 20 changed files with 3,645 additions and 160 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/ci-as-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: ci-as-lint
on:
push:
branches:
- main
pull_request:
types:
- opened
- synchronize
- reopened
- ready_for_review
jobs:
get-dirs:
name: Get Directories
runs-on: ubuntu-latest
outputs:
dirs: ${{ steps.get-dirs.outputs.dirs }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Get subdirectories
id: get-dirs
# we need to lint the src directory and all the examples
run: echo "dirs=$(ls -d examples/*/ | jq -Rsc '["src/"] + split("\n")[:-1]' )" >> ${GITHUB_OUTPUT}

as-lint:
needs: get-dirs
if: github.event_name == 'pull_request'
name: Lint
runs-on: ubuntu-latest
strategy:
matrix:
dir: ${{ fromJson(needs.get-dirs.outputs.dirs) }}
defaults:
run:
working-directory: ${{ matrix.dir }}
steps:
- uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: ">=20"
- name: Check Node and NPM versions
run: |
node --version
npm --version
- name: Install dependencies
run: npm install
- name: Validate code is formatted
run: npm run pretty:check
- name: Valid code is linted
run: npm run lint
11 changes: 11 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"editor.formatOnSave": true,
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[graphql]": {
"editor.formatOnSave": false
}
}
13 changes: 13 additions & 0 deletions examples/hmplugin1/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"env": {
"es6": true
},
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": ["@typescript-eslint"],
"rules": {}
}
2 changes: 2 additions & 0 deletions examples/hmplugin1/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# don't run prettier on graphql files, because it places every directive on a new line
*.graphql
3 changes: 3 additions & 0 deletions examples/hmplugin1/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"plugins": ["assemblyscript-prettier"]
}
15 changes: 8 additions & 7 deletions examples/hmplugin1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Try some graphql queries on the Dgraph endpoint:

```graphql
{
getFullName(firstName: "John", lastName:"Doe")
getFullName(firstName: "John", lastName: "Doe")
}
```

Expand All @@ -55,13 +55,14 @@ These will invoke the respective Hypermode functions within `hmplugin1`.
Next, try adding some data:

```graphql

mutation {
addPerson(input: [
{ firstName: "Harry", lastName: "Potter" },
{ firstName: "Tom", lastName: "Riddle" },
{ firstName: "Albus", lastName: "Dumbledore" }
]) {
addPerson(
input: [
{ firstName: "Harry", lastName: "Potter" }
{ firstName: "Tom", lastName: "Riddle" }
{ firstName: "Albus", lastName: "Dumbledore" }
]
) {
person {
id
firstName
Expand Down
21 changes: 13 additions & 8 deletions examples/hmplugin1/assembly/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ export function getFullName(firstName: string, lastName: string): string {

export function getPeople(): string {
const people = [
<Person> {firstName: "Bob", lastName: "Smith"},
<Person> {firstName: "Alice", lastName: "Jones"}
<Person>{ firstName: "Bob", lastName: "Smith" },
<Person>{ firstName: "Alice", lastName: "Jones" },
];

people.forEach(p => p.updateFullName());
people.forEach((p) => p.updateFullName());
return JSON.stringify(people);
}

Expand All @@ -32,7 +32,7 @@ export function queryPeople1(): string {

const response = dql.query<PeopleData>(query);
const people = response.data.people;
people.forEach(p => p.updateFullName());
people.forEach((p) => p.updateFullName());
return JSON.stringify(people);
}

Expand All @@ -47,7 +47,7 @@ export function queryPeople2(): string {
}
}
`;

const results = graphql.execute<PeopleData>(statement);

// completely optional, but let's log some tracing info
Expand Down Expand Up @@ -87,7 +87,7 @@ export function newPerson2(firstName: string, lastName: string): string {
`;

const response = graphql.execute<AddPersonPayload>(statement);
return response.data.addPerson.people[0].id!;
return response.data.addPerson.people[0].id!;
}

function getPersonCount(): i32 {
Expand All @@ -105,7 +105,7 @@ function getPersonCount(): i32 {

export function getRandomPerson(): string {
const count = getPersonCount();
const offset = <u32> Math.floor(Math.random() * count);
const offset = <u32>Math.floor(Math.random() * count);
const statement = `
query {
people: queryPerson(first: 1, offset: ${offset}) {
Expand All @@ -116,11 +116,12 @@ export function getRandomPerson(): string {
}
}
`;

const results = graphql.execute<PeopleData>(statement);
return JSON.stringify(results.data.people[0]);
}


@json
class Person {
id: string | null = null;
Expand All @@ -133,21 +134,25 @@ class Person {
}
}


@json
class PeopleData {
people!: Person[];
}


@json
class AddPersonPayload {
addPerson!: PeopleData;
}


@json
class AggregatePersonResult {
aggregatePerson!: GQLAggregateValues;
}


@json
class GQLAggregateValues {
count: u32 = 0;
Expand Down
4 changes: 1 addition & 3 deletions examples/hmplugin1/assembly/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
"extends": "assemblyscript/std/assembly.json",
"include": [
"./**/*.ts"
]
"include": ["./**/*.ts"],
}
Loading

0 comments on commit b7581ba

Please sign in to comment.