Skip to content

Replace TSLint with ESLint and Prettier #2112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
50 changes: 23 additions & 27 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.191.1/containers/javascript-node
{
"name": "Node.js",
"build": {
"dockerfile": "Dockerfile",
// Update 'VARIANT' to pick a Node version: 14, 16
"args": {
"VARIANT": "14"
}
},
// Set *default* container specific settings.json values on container create.
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"esbenp.prettier-vscode",
"ms-vscode.vscode-typescript-tslint-plugin",
"vue.volar"
],
"settings": {
"editor.formatOnSave": false,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"prettier.jsxSingleQuote": true,
"prettier.singleQuote": true
},

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "npm ci && npm run init && npm run build",
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "node"
}
"name": "Node.js",
"build": {
"dockerfile": "Dockerfile",
// Update 'VARIANT' to pick a Node version: 14, 16
"args": {
"VARIANT": "14"
}
},
// Set *default* container specific settings.json values on container create.
// Add the IDs of extensions you want installed when the container is created.
"customizations": {
"extensions": [
"DavidAnson.vscode-markdownlint",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"vue.volar"
]
},
// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "npm ci && npm run init && npm run build",
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "node"
}
4 changes: 1 addition & 3 deletions .github/config/changelog.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@
"sort": "DESC",
"pr_template": "- [${{LABELS}}] ${{TITLE}} (#${{NUMBER}})",
"template": "${{UNCATEGORIZED}}",
"ignore_labels": [
"dependencies"
]
"ignore_labels": ["dependencies"]
}
55 changes: 29 additions & 26 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,32 @@ jobs:
- windows-latest
name: Run on ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Setup node
uses: actions/setup-node@v2
with:
node-version: 14
- name: Build
run: |
npm ci
npm run init
npm run build
npm run bundle
- name: Test
if: matrix.os == 'windows-latest'
run: |
npm run test
- name: Test & Coverage
if: matrix.os == 'ubuntu-latest'
run: |
npm run test-cov
npm run check-format
npm run merge-report && cat coverage/lcov.info
- name: Upload Coveralls Report
if: success() && matrix.os == 'ubuntu-latest'
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v2
- name: Setup node
uses: actions/setup-node@v2
with:
node-version: 14
- name: Build
run: |
npm ci
npm run init
npm run build
npm run bundle
- name: Lint
if: matrix.os == 'ubuntu-latest'
run: npm run lint
- name: Test
if: matrix.os == 'windows-latest'
run: |
npm run test
- name: Test & Coverage
if: matrix.os == 'ubuntu-latest'
run: |
npm run test-cov
npm run check-format
npm run merge-report && cat coverage/lcov.info
- name: Upload Coveralls Report
if: success() && matrix.os == 'ubuntu-latest'
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

jobs:
release:
if: |
if: |
startsWith(github.ref, 'refs/tags/v') &&
!contains(github.ref, 'alpha') &&
!contains(github.ref, 'beta') &&
Expand Down
2 changes: 0 additions & 2 deletions .prettierrc

This file was deleted.

6 changes: 6 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
$schema: 'http://json.schemastore.org/prettierrc',
singleQuote: true,
jsxSingleQuote: true,
endOfLine: 'auto',
};
5 changes: 2 additions & 3 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp

// List of extensions which should be recommended for users of this workspace.
"recommendations": [
"DavidAnson.vscode-markdownlint",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"ms-vscode.vscode-typescript-tslint-plugin",
"ms-vscode-remote.remote-containers"

],
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
"unwantedRecommendations": []
Expand Down
51 changes: 47 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,49 @@
{
"editor.formatOnSave": false,
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact",
"vue"
],
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"prettier.jsxSingleQuote": true,
"prettier.singleQuote": true
}
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
},
"[javascriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
},
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
},
"[typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
},
"[vue]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
},
"search.exclude": {
"**/docs": true,
"**/node_modules": true,
"**/lib": true
}
}
90 changes: 52 additions & 38 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,16 @@ interface TesterContext {
config: any;
}

type Tester = (uischema: UISchemaElement, schema: JsonSchema, context: TesterContext) => boolean;
type RankedTester = (uischema: UISchemaElement, schema: JsonSchema, context: TesterContext) => number;
type Tester = (
uischema: UISchemaElement,
schema: JsonSchema,
context: TesterContext
) => boolean;
type RankedTester = (
uischema: UISchemaElement,
schema: JsonSchema,
context: TesterContext
) => number;
```

This allows the testers to resolve any `$ref` they might encounter in their handed over `schema` by using the context's `rootSchema`.
Expand All @@ -50,30 +58,37 @@ To restore the old behavior, you can use `json-schema-ref-parser` or other libra
```ts
import React, { useState } from 'react';
import { JsonForms } from '@jsonforms/react';
import { materialCells, materialRenderers } from '@jsonforms/material-renderers';
import {
materialCells,
materialRenderers,
} from '@jsonforms/material-renderers';
import $RefParser from '@apidevtools/json-schema-ref-parser';
import JsonRefs from 'json-refs';

import mySchemaWithReferences from 'myschema.json';

const refParserOptions = {
dereference: {
circular: false
}
}
circular: false,
},
};

function App() {
const [data, setData] = useState(initialData);
const [resolvedSchema, setSchema] = useState();

useEffect(() => {
$RefParser.dereference(mySchemaWithReferences).then(res => setSchema(res.$schema));
$RefParser
.dereference(mySchemaWithReferences)
.then((res) => setSchema(res.$schema));
// or
JsonRefs.resolveRefs(mySchemaWithReferences).then(res => setSchema(res.resolved));
},[]);
JsonRefs.resolveRefs(mySchemaWithReferences).then((res) =>
setSchema(res.resolved)
);
}, []);

if(resolvedSchema === undefined) {
return <div> Loading... </div>
if (resolvedSchema === undefined) {
return <div> Loading... </div>;
}

return (
Expand Down Expand Up @@ -143,12 +158,12 @@ export const schema = {
type: 'object',
properties: {
name: {
type: 'string'
}
type: 'string',
},
},
required: ['name']
required: ['name'],
};
export const data = {name: 'Send email to Adrian'};
export const data = { name: 'Send email to Adrian' };

@Component({
selector: 'app-root',
Expand All @@ -160,7 +175,7 @@ export const data = {name: 'Send email to Adrian'};
[renderers]="renderers"
(dataChange)="onDataChange($event)"
></jsonforms>
`
`,
})
export class AppComponent {
readonly renderers = angularMaterialRenderers;
Expand Down Expand Up @@ -201,15 +216,12 @@ All current Redux functionally can also be achieved with the standalone version.
Previously the store was initialized like this:

```ts
const store = createStore(
combineReducers({ jsonforms: jsonformsReducer() }),
{
jsonforms: {
cells: materialCells,
renderers: materialRenderers
}
}
);
const store = createStore(combineReducers({ jsonforms: jsonformsReducer() }), {
jsonforms: {
cells: materialCells,
renderers: materialRenderers,
},
});
store.dispatch(Actions.init(data, schema, uischema));
return (
<Provider store={store}>
Expand Down Expand Up @@ -250,7 +262,7 @@ Within the standalone version, the renderer can just be provided to the `<JsonFo
const renderers = [
...materialRenderers,
// register custom renderer
{ tester: customControlTester, renderer: CustomControl }
{ tester: customControlTester, renderer: CustomControl },
];

const MyApp = () => (
Expand All @@ -259,7 +271,6 @@ const MyApp = () => (
renderers={renderers}
/>
);

```

##### Example 3: Listen to data and validation changes
Expand All @@ -286,7 +297,10 @@ If you want to keep using the Redux variant of JSON Forms for now (which is not
The new imports are available at `@jsonforms/react/lib/redux`, i.e.

```ts
import { jsonformsReducer, JsonFormsReduxProvider } from '@jsonforms/react/lib/redux';
import {
jsonformsReducer,
JsonFormsReduxProvider,
} from '@jsonforms/react/lib/redux';
```

## Migrating from JSON Forms 1.x (AngularJS 1.x)
Expand All @@ -298,8 +312,8 @@ The complexity of the migration of an existing JSON Forms 1.x application, which
There are two big changes between JSON Forms 1 and JSON Forms 2 you need to understand when migrating your existing application.

1. JSON Forms 2.x does not rely on any specific UI framework [or library].
The `2.0.0` initial release featured renderers based on [React](https://reactjs.org).
An [Angular](https://angular.io) based renderer set was released with `2.1.0`.
The `2.0.0` initial release featured renderers based on [React](https://reactjs.org).
An [Angular](https://angular.io) based renderer set was released with `2.1.0`.

2. Since JSON Forms 2.x maintains its internal state via [redux](https://redux.js.org/), you will need to add it as a dependency to your application.

Expand All @@ -314,20 +328,20 @@ Instead of:

```ts
const uischema = {
type: 'Control',
scope: {
$ref: '#/properties/name'
}
}
type: 'Control',
scope: {
$ref: '#/properties/name',
},
};
```

simply write:

```ts
const uischema = {
type: 'Control',
scope: '#/properties/name'
}
type: 'Control',
scope: '#/properties/name',
};
```

Otherwise the UI schema remains unchanged and works like in JSON Forms 1.x.
Expand Down
Loading