Skip to content

Commit

Permalink
Merge pull request #13 from PADAS/10-fix-lint-errors
Browse files Browse the repository at this point in the history
Fix lint errors
  • Loading branch information
doneill authored Apr 22, 2024
2 parents 497d86e + 333ac17 commit eb0d10e
Show file tree
Hide file tree
Showing 11 changed files with 279 additions and 228 deletions.
4 changes: 2 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
preset: "ts-jest",
testEnvironment: "node",
};
31 changes: 20 additions & 11 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
/* eslint-env node */
module.exports = {
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
parser: '@typescript-eslint/parser',
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaVersion: 13,
project: './tsconfig.json',
sourceType: 'module',
project: "./tsconfig.eslint.json",
tsconfigRootDir: __dirname,
sourceType: "module",
},
plugins: ['@typescript-eslint'],
overrides: [
{
files: ["test/**/*.{ts,tsx}"],
parserOptions: {
project: "./tsconfig.test.json",
},
},
],
plugins: ["@typescript-eslint"],
rules: {
'import/prefer-default-export': 'off',
'react/require-default-props': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'no-plusplus': [2, { allowForLoopAfterthoughts: true }]
},
"import/prefer-default-export": "off",
"react/require-default-props": "off",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-explicit-any": "off",
"no-plusplus": [2, { allowForLoopAfterthoughts: true }],
},
root: true,
};
25 changes: 17 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# React Native JSONForms Formatter

![Build Status][ci-url]

[ci-url]: https://github.com/PADAS/react-native-jsonforms-formatter/actions/workflows/npm-build.yml/badge.svg
Expand All @@ -22,14 +23,15 @@ npm install --save react-native-jsonforms-formatter
```

## Usage

The library provides two main functions: `validateJSONSchema` and `generateUISchema`.

### Validating JSONSchema

You can use the `validateJSONSchema` function to validate a JSONSchema string:

```typescript
import { validateJSONSchema } from 'react-native-jsonforms-formatter';
import { validateJSONSchema } from "react-native-jsonforms-formatter";

const stringSchema = `
{
Expand All @@ -47,30 +49,35 @@ const stringSchema = `
}
`;

const jsonSchema = validateJSONSchema(stringSchema);
const jsonSchema = validateJSONSchema(stringSchema);
```

The `validateJSONSchema` function returns a valid JSONSchema object if the input string is a valid JSONSchema. If the input is not valid, it will throw an error.

### Generating UISchema

You can use the `generateUISchema` function to generate a UISchema object from a valid JSONSchema:

```typescript
import { generateUISchema } from 'react-native-jsonforms-formatter';
import { generateUISchema } from "react-native-jsonforms-formatter";

const uiSchema = generateUISchema(jsonSchema);
```

The `generateUISchema` function returns a `UISchema` object that can be used with the ReactNative JSONForms library.

## Putting it all together

Here's an example of how you can use the library in a ReactNative application:

```typescript
import React from 'react';
import { JsonForms } from '@jsonforms/react-native';
import { validateJSONSchema, generateUISchema } from 'react-native-jsonforms-formatter';
import { RNRenderers, RNCells } from '@jsonforms/react-native-renderers';
import { JsonForms } from "@jsonforms/react-native";
import { RNCells, RNRenderers } from "@jsonforms/react-native-renderers";
import React from "react";
import {
generateUISchema,
validateJSONSchema,
} from "react-native-jsonforms-formatter";

const stringSchema = `
{
Expand All @@ -92,7 +99,7 @@ const jsonSchema = validateJSONSchema(stringSchema);
const uiSchema = generateUISchema(jsonSchema);

const App = () => {
const [data, setData] = React.useState({ name: 'John Doe', age: 30 });
const [data, setData] = React.useState({ name: "John Doe", age: 30 });

return (
<JsonForms
Expand All @@ -110,11 +117,13 @@ export default App;
```

## Contributors

Contributions are welcome! If you find a bug or have a feature request, please open an issue.

<a href="https://github.com/PADAS/react-native-jsonforms-formatter/graphs/contributors">
<img src="https://contributors-img.web.app/image?repo=PADAS/react-native-jsonforms-formatter" />
</a>

## Licensing

A copy of the license is available in the repository's [LICENSE](LICENSE) file.
6 changes: 3 additions & 3 deletions babel.config.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
presets: [
['@babel/preset-env', {targets: {node: 'current'}}],
'@babel/preset-typescript',
["@babel/preset-env", { targets: { node: "current" } }],
"@babel/preset-typescript",
],
};
};
3 changes: 1 addition & 2 deletions extJestSetup.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
import * as matchers from 'jest-extended';
import * as matchers from "jest-extended";
expect.extend(matchers);

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"build": "npx webpack",
"clean": "rm -rf dist",
"lint": "eslint src/ --ext .js,.jsx,.ts,.tsx",
"lint:test": "eslint 'test/**/*.{ts,tsx}'",
"test": "jest test/.*\\.test\\..* --coverage",
"typecheck": "tsc -b"
},
Expand Down Expand Up @@ -73,4 +74,4 @@
"webpack": "^5.91.0",
"webpack-cli": "^5.1.4"
}
}
}
Loading

0 comments on commit eb0d10e

Please sign in to comment.