├── commitlint.config.js ├── packages ├── jsonld-lint-vscode │ ├── .gitignore │ ├── assets │ │ └── vscode.gif │ ├── .vscodeignore │ ├── README.md │ ├── src │ │ ├── test │ │ │ ├── suite │ │ │ │ ├── extension.test.ts │ │ │ │ └── index.ts │ │ │ └── runTest.ts │ │ └── index.ts │ ├── tsconfig.json │ ├── CHANGELOG.md │ └── package.json ├── jsonld-lint │ ├── __tests__ │ │ ├── __fixtures__ │ │ │ ├── 0002-in.json │ │ │ ├── 0003-in.json │ │ │ ├── 0010-in.json │ │ │ ├── 0005-in.json │ │ │ ├── 0006-in.json │ │ │ ├── 0004-in.json │ │ │ ├── 0007-in.json │ │ │ ├── 0011-in.json │ │ │ ├── 0008-in.json │ │ │ ├── 0009-in.json │ │ │ ├── 0001-in.json │ │ │ ├── 0011-out.json │ │ │ ├── 0010-out.json │ │ │ ├── 0002-out.json │ │ │ ├── 0003-out.json │ │ │ ├── 0006-out.json │ │ │ ├── 0004-out.json │ │ │ ├── 0005-out.json │ │ │ ├── 0007-out.json │ │ │ ├── 0009-out.json │ │ │ ├── 0008-out.json │ │ │ ├── 0001-out.json │ │ │ └── index.ts │ │ ├── lintCompactDocument.spec.ts │ │ └── utilities.ts │ ├── tsconfig.json │ ├── src │ │ ├── types │ │ │ ├── ContextResolver.ts │ │ │ ├── jsonld.d.ts │ │ │ ├── JsonLdDocumentLintRule.ts │ │ │ ├── DocumentPosition.ts │ │ │ ├── JsonLdDocumentTermInfo.ts │ │ │ ├── JsonLdLintOptions.ts │ │ │ ├── JsonLdLintError.ts │ │ │ ├── JsonLdDocumentProcessingResult.ts │ │ │ ├── JsonLdDocumentContext.ts │ │ │ ├── JsonLdDocumentTermContext.ts │ │ │ ├── JsonLdDocumentLintResult.ts │ │ │ ├── JsonLdDocumentTerm.ts │ │ │ ├── KnownJsonLdTerm.ts │ │ │ ├── JsonLdDocumentProcessingContext.ts │ │ │ ├── JsonLdObjectType.ts │ │ │ ├── index.ts │ │ │ └── JsonLdDocumentSyntaxError.ts │ │ ├── utilities.ts │ │ ├── jsonldDocumentProcessor.ts │ │ └── index.ts │ ├── package.json │ ├── jest.config.js │ ├── CHANGELOG.md │ └── README.md └── jsonld-lint-cli │ ├── assets │ └── cli.gif │ ├── tsconfig.json │ ├── CHANGELOG.md │ ├── package.json │ ├── src │ ├── index.js │ ├── cli.ts │ └── utilities.ts │ ├── README.md │ └── jest.config.js ├── .husky ├── commit-msg └── pre-commit ├── tsconfig.json ├── config └── tsconfig.base.json ├── lerna.json ├── .github ├── workflows │ ├── any.pr.yml │ ├── github_backup.yaml │ ├── push-master.yml │ └── push-release.yml └── pull_request_template.md ├── .eslintrc.json ├── .gitignore ├── docs ├── assets │ ├── mattr-logo-square.svg │ └── mattr-logo-tm.svg ├── RELEASE.md └── CONTRIBUTING.md ├── package.json ├── README.md └── LICENSE /commitlint.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { extends: ["@commitlint/config-conventional"] }; 2 | -------------------------------------------------------------------------------- /packages/jsonld-lint-vscode/.gitignore: -------------------------------------------------------------------------------- 1 | out 2 | node_modules 3 | .vscode-test/ 4 | *.vsix 5 | -------------------------------------------------------------------------------- /packages/jsonld-lint/__tests__/__fixtures__/0002-in.json: -------------------------------------------------------------------------------- 1 | { 2 | "@context": false 3 | } 4 | -------------------------------------------------------------------------------- /packages/jsonld-lint/__tests__/__fixtures__/0003-in.json: -------------------------------------------------------------------------------- 1 | { 2 | "@context": 100 3 | } 4 | -------------------------------------------------------------------------------- /packages/jsonld-lint/__tests__/__fixtures__/0010-in.json: -------------------------------------------------------------------------------- 1 | { 2 | "@context": {}, 3 | "": false 4 | } 5 | -------------------------------------------------------------------------------- /packages/jsonld-lint/__tests__/__fixtures__/0005-in.json: -------------------------------------------------------------------------------- 1 | { 2 | "@context": { 3 | "@version": false 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /packages/jsonld-lint/__tests__/__fixtures__/0006-in.json: -------------------------------------------------------------------------------- 1 | { 2 | "@context": { 3 | "@version": 100 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /.husky/commit-msg: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | [[ -n $HUSKY_BYPASS ]] || yarn commitlint --edit $1 5 | -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | [[ -n $HUSKY_BYPASS ]] || yarn pretty-quick --staged 5 | -------------------------------------------------------------------------------- /packages/jsonld-lint/__tests__/__fixtures__/0004-in.json: -------------------------------------------------------------------------------- 1 | { 2 | "@context": { 3 | "@version": "a string" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /packages/jsonld-lint/__tests__/__fixtures__/0007-in.json: -------------------------------------------------------------------------------- 1 | { 2 | "@context": { 3 | "@notAValidProperty": 100 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /packages/jsonld-lint/__tests__/__fixtures__/0011-in.json: -------------------------------------------------------------------------------- 1 | { 2 | "@context": { 3 | "termDefinition": "@context" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /packages/jsonld-lint-cli/assets/cli.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattrglobal/jsonld-lint/HEAD/packages/jsonld-lint-cli/assets/cli.gif -------------------------------------------------------------------------------- /packages/jsonld-lint/__tests__/__fixtures__/0008-in.json: -------------------------------------------------------------------------------- 1 | { 2 | "@context": {}, 3 | "id": "some-id", 4 | "@id": "some-duplicate-id" 5 | } 6 | -------------------------------------------------------------------------------- /packages/jsonld-lint/__tests__/__fixtures__/0009-in.json: -------------------------------------------------------------------------------- 1 | { 2 | "@context": {}, 3 | "id": "some-id", 4 | "id": "some-duplicate-id" 5 | } 6 | -------------------------------------------------------------------------------- /packages/jsonld-lint-vscode/assets/vscode.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattrglobal/jsonld-lint/HEAD/packages/jsonld-lint-vscode/assets/vscode.gif -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./config/tsconfig.base.json", 3 | "include": ["packages/**/src"], 4 | "exclude": ["**/node_modules/**"] 5 | } 6 | -------------------------------------------------------------------------------- /packages/jsonld-lint/__tests__/__fixtures__/0001-in.json: -------------------------------------------------------------------------------- 1 | { 2 | "@context": { 3 | "definedTerm": "https://example.com/definedTerm" 4 | }, 5 | "definedTerm": "good", 6 | "undefinedTerm": "bad" 7 | } 8 | -------------------------------------------------------------------------------- /packages/jsonld-lint-vscode/.vscodeignore: -------------------------------------------------------------------------------- 1 | .vscode/** 2 | .vscode-test/** 3 | out/test/** 4 | src/** 5 | .gitignore 6 | vsc-extension-quickstart.md 7 | **/tsconfig.json 8 | **/.eslintrc.json 9 | **/*.map 10 | **/*.ts 11 | -------------------------------------------------------------------------------- /packages/jsonld-lint/__tests__/__fixtures__/0011-out.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "type": "jsonld-lint-result/term-definition", 4 | "name": "@context", 5 | "iri": "https://www.w3.org/TR/json-ld11/#the-context", 6 | "isJsonLdKeyword": true, 7 | "documentPosition": { 8 | "startPositionOffset": 4, 9 | "endPositionOffset": 14 10 | } 11 | } 12 | ] 13 | -------------------------------------------------------------------------------- /config/tsconfig.base.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "target": "es6", 5 | "lib": ["es6"], 6 | "sourceMap": true, 7 | "allowJs": false, 8 | "moduleResolution": "node", 9 | "strict": true, 10 | "declaration": true, 11 | "downlevelIteration": true, 12 | "types": ["node", "jest"], 13 | "typeRoots": ["../node_modules/@types"], 14 | "baseUrl": ".", 15 | "resolveJsonModule": true 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /packages/jsonld-lint-cli/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "target": "es5", 5 | "sourceMap": true, 6 | "allowJs": false, 7 | "moduleResolution": "node", 8 | "strict": true, 9 | "declaration": true, 10 | "downlevelIteration": true, 11 | "baseUrl": ".", 12 | "esModuleInterop": true, 13 | "resolveJsonModule": true, 14 | "outDir": "./bin", 15 | "types": ["jest", "node"] 16 | }, 17 | "include": ["./src"] 18 | } 19 | -------------------------------------------------------------------------------- /packages/jsonld-lint/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "target": "es5", 5 | "sourceMap": true, 6 | "allowJs": false, 7 | "moduleResolution": "node", 8 | "strict": true, 9 | "declaration": true, 10 | "downlevelIteration": true, 11 | "baseUrl": ".", 12 | "esModuleInterop": true, 13 | "resolveJsonModule": true, 14 | "outDir": "./lib", 15 | "types": ["jest", "node"] 16 | }, 17 | "include": ["./src"] 18 | } 19 | -------------------------------------------------------------------------------- /packages/jsonld-lint-vscode/README.md: -------------------------------------------------------------------------------- 1 | ![Mattr logo](../../docs/assets/mattr-black.svg) 2 | 3 | # JSON-LD Lint VS-Code Extension 4 | 5 | ![push-master](https://github.com/mattrglobal/jsonld-lint/workflows/push-master/badge.svg) 6 | ![push-release](https://github.com/mattrglobal/jsonld-lint/workflows/push-release/badge.svg) 7 | 8 | _Coming soon_ 9 | 10 | The jsonld-lint engine bundled as a [vscode](https://code.visualstudio.com/) extension. 11 | 12 |

13 | -------------------------------------------------------------------------------- /lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "independent", 3 | "npmClient": "yarn", 4 | "npmClientArgs": ["--no-optional", "--frozen-lockfile"], 5 | "useWorkspaces": true, 6 | "packages": ["packages/*"], 7 | "command": { 8 | "publish": { 9 | "allowBranch": ["master"], 10 | "conventionalCommits": true, 11 | "verifyAccess": false 12 | }, 13 | "version": { 14 | "allowBranch": ["release"], 15 | "conventionalCommits": true, 16 | "message": "chore(release): publish [skip ci]" 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /packages/jsonld-lint-vscode/src/test/suite/extension.test.ts: -------------------------------------------------------------------------------- 1 | import * as assert from "assert"; 2 | 3 | // You can import and use all API from the 'vscode' module 4 | // as well as import your extension to test it 5 | import * as vscode from "vscode"; 6 | // import * as myExtension from '../../extension'; 7 | 8 | suite("Extension Test Suite", () => { 9 | vscode.window.showInformationMessage("Start all tests."); 10 | 11 | test("Sample test", () => { 12 | assert.equal(-1, [1, 2, 3].indexOf(5)); 13 | assert.equal(-1, [1, 2, 3].indexOf(0)); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /.github/workflows/any.pr.yml: -------------------------------------------------------------------------------- 1 | name: any-pr 2 | 3 | on: [pull_request] 4 | 5 | jobs: 6 | build_test: 7 | name: Build test 8 | runs-on: ubuntu-latest 9 | strategy: 10 | matrix: 11 | node-version: [18.x, 20.x, 22.x] 12 | steps: 13 | - uses: actions/checkout@v4 14 | - name: Use Node.js ${{ matrix.node-version }} 15 | uses: actions/setup-node@v4 16 | with: 17 | node-version: ${{ matrix.node-version }} 18 | - run: yarn install --frozen-lockfile 19 | - run: yarn lint 20 | - run: yarn build 21 | - run: yarn test 22 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | "parser": "@typescript-eslint/parser", 4 | "parserOptions": { 5 | "ecmaVersion": 6, 6 | "sourceType": "module" 7 | }, 8 | "plugins": ["@typescript-eslint", "node"], 9 | "extends": [ 10 | "eslint:recommended", 11 | "plugin:@typescript-eslint/eslint-recommended", 12 | "plugin:@typescript-eslint/recommended", 13 | "plugin:prettier/recommended" 14 | ], 15 | "rules": { 16 | "@typescript-eslint/explicit-function-return-type": "error", 17 | "@typescript-eslint/no-explicit-any": "error", 18 | "node/no-extraneous-import": "error" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /packages/jsonld-lint/__tests__/__fixtures__/0010-out.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "type": "jsonld-lint-result/term-definition", 4 | "name": "@context", 5 | "iri": "https://www.w3.org/TR/json-ld11/#the-context", 6 | "isJsonLdKeyword": true, 7 | "documentPosition": { 8 | "startPositionOffset": 4, 9 | "endPositionOffset": 14 10 | } 11 | }, 12 | { 13 | "type": "jsonld-lint-result/syntax-error", 14 | "rule": "jsonld-lint/empty-json-property-key", 15 | "message": "Empty JSON property encountered", 16 | "documentPosition": { 17 | "startPositionOffset": 22, 18 | "endPositionOffset": 24 19 | } 20 | } 21 | ] 22 | -------------------------------------------------------------------------------- /packages/jsonld-lint/__tests__/__fixtures__/0002-out.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "type": "jsonld-lint-result/term-definition", 4 | "name": "@context", 5 | "isJsonLdKeyword": true, 6 | "documentPosition": { 7 | "startPositionOffset": 4, 8 | "endPositionOffset": 14 9 | } 10 | }, 11 | { 12 | "type": "jsonld-lint-result/syntax-error", 13 | "rule": "jsonld-lint/unexpected-json-value-type", 14 | "message": "Value type for the JSON-LD keyword \"@context\" of \"boolean\" is invalid, expected one of type: string,array,object", 15 | "documentPosition": { 16 | "startPositionOffset": 16, 17 | "endPositionOffset": 21 18 | }, 19 | "value": "@context" 20 | } 21 | ] 22 | -------------------------------------------------------------------------------- /packages/jsonld-lint/__tests__/__fixtures__/0003-out.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "type": "jsonld-lint-result/term-definition", 4 | "name": "@context", 5 | "isJsonLdKeyword": true, 6 | "documentPosition": { 7 | "startPositionOffset": 4, 8 | "endPositionOffset": 14 9 | } 10 | }, 11 | { 12 | "type": "jsonld-lint-result/syntax-error", 13 | "rule": "jsonld-lint/unexpected-json-value-type", 14 | "message": "Value type for the JSON-LD keyword \"@context\" of \"number\" is invalid, expected one of type: string,array,object", 15 | "documentPosition": { 16 | "startPositionOffset": 16, 17 | "endPositionOffset": 19 18 | }, 19 | "value": "@context" 20 | } 21 | ] 22 | -------------------------------------------------------------------------------- /packages/jsonld-lint-vscode/src/test/runTest.ts: -------------------------------------------------------------------------------- 1 | import * as path from "path"; 2 | 3 | import { runTests } from "vscode-test"; 4 | 5 | async function main() { 6 | try { 7 | // The folder containing the Extension Manifest package.json 8 | // Passed to `--extensionDevelopmentPath` 9 | const extensionDevelopmentPath = path.resolve(__dirname, "../../"); 10 | 11 | // The path to test runner 12 | // Passed to --extensionTestsPath 13 | const extensionTestsPath = path.resolve(__dirname, "./suite/index"); 14 | 15 | // Download VS Code, unzip it and run the integration test 16 | await runTests({ extensionDevelopmentPath, extensionTestsPath }); 17 | } catch (err) { 18 | console.error("Failed to run tests"); 19 | process.exit(1); 20 | } 21 | } 22 | 23 | main(); 24 | -------------------------------------------------------------------------------- /packages/jsonld-lint-vscode/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "target": "es6", 5 | "outDir": "out", 6 | "lib": ["es6"], 7 | "noImplicitAny": false, 8 | "noImplicitReturns": true, 9 | "sourceMap": true, 10 | "rootDir": "src", 11 | "esModuleInterop": true, 12 | "strict": true /* enable all strict type-checking options */, 13 | "types": ["node"] 14 | /* Additional Checks */ 15 | // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ 16 | // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ 17 | // "noUnusedParameters": true, /* Report errors on unused parameters. */ 18 | }, 19 | "exclude": ["node_modules", ".vscode-test"] 20 | } 21 | -------------------------------------------------------------------------------- /packages/jsonld-lint-cli/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | # [0.4.0](https://github.com/mattrglobal/jsonld-lint/compare/jsonld-lint-cli@0.3.0...jsonld-lint-cli@0.4.0) (2022-06-22) 7 | 8 | **Note:** Version bump only for package jsonld-lint-cli 9 | 10 | # [0.3.0](https://github.com/mattrglobal/jsonld-lint/compare/jsonld-lint-cli@0.2.0...jsonld-lint-cli@0.3.0) (2020-10-29) 11 | 12 | **Note:** Version bump only for package jsonld-lint-cli 13 | 14 | # [0.2.0](https://github.com/mattrglobal/jsonld-lint/compare/jsonld-lint-cli@0.1.0...jsonld-lint-cli@0.2.0) (2020-10-09) 15 | 16 | **Note:** Version bump only for package jsonld-lint-cli 17 | 18 | # 0.1.0 (2020-10-08) 19 | 20 | Initial release 21 | -------------------------------------------------------------------------------- /packages/jsonld-lint/src/types/ContextResolver.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 - MATTR Limited 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | /** 15 | * A JSON-LD Context resolver 16 | */ 17 | export declare class ContextResolver { 18 | constructor(options: any); 19 | 20 | resolve(options: any): Promise; 21 | } 22 | -------------------------------------------------------------------------------- /packages/jsonld-lint/src/types/jsonld.d.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 - MATTR Limited 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | /** 15 | * Declare placeholder module for missing types for jsonld.js 16 | */ 17 | declare module "jsonld"; 18 | declare module "jsonld/lib/context"; 19 | declare module "jsonld/lib/ContextResolver"; 20 | -------------------------------------------------------------------------------- /packages/jsonld-lint-vscode/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | # [0.4.0](https://github.com/mattrglobal/jsonld-lint/compare/jsonld-lint-vscode@0.3.0...jsonld-lint-vscode@0.4.0) (2022-06-22) 7 | 8 | **Note:** Version bump only for package jsonld-lint-vscode 9 | 10 | # [0.3.0](https://github.com/mattrglobal/jsonld-lint/compare/jsonld-lint-vscode@0.2.0...jsonld-lint-vscode@0.3.0) (2020-10-29) 11 | 12 | **Note:** Version bump only for package jsonld-lint-vscode 13 | 14 | # [0.2.0](https://github.com/mattrglobal/jsonld-lint/compare/jsonld-lint-vscode@0.1.0...jsonld-lint-vscode@0.2.0) (2020-10-09) 15 | 16 | **Note:** Version bump only for package jsonld-lint-vscode 17 | 18 | # 0.1.0 (2020-10-08) 19 | 20 | Initial release 21 | -------------------------------------------------------------------------------- /packages/jsonld-lint/__tests__/__fixtures__/0006-out.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "type": "jsonld-lint-result/term-definition", 4 | "name": "@context", 5 | "isJsonLdKeyword": true, 6 | "documentPosition": { 7 | "startPositionOffset": 4, 8 | "endPositionOffset": 14 9 | } 10 | }, 11 | { 12 | "type": "jsonld-lint-result/term-definition", 13 | "name": "@version", 14 | "isJsonLdKeyword": true, 15 | "documentPosition": { 16 | "startPositionOffset": 22, 17 | "endPositionOffset": 32 18 | } 19 | }, 20 | { 21 | "type": "jsonld-lint-result/syntax-error", 22 | "rule": "jsonld-lint/unexpected-json-value", 23 | "message": "Value for the JSON-LD keyword \"@version\" of \"100\" is invalid, expected one of: 1,1,1.1", 24 | "value": "@version", 25 | "documentPosition": { 26 | "startPositionOffset": 34, 27 | "endPositionOffset": 37 28 | } 29 | } 30 | ] 31 | -------------------------------------------------------------------------------- /packages/jsonld-lint/src/types/JsonLdDocumentLintRule.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 - MATTR Limited 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | /** 15 | * Result from processing a JSON-LD Document 16 | */ 17 | export enum JsonLdDocumentLintRule { 18 | UnrecognizedJsonLdKeyword = "jsonld-lint/unrecognized-jsonld-keyword", 19 | UnmappedTerm = "jsonld-lint/unmapped-term", 20 | } 21 | -------------------------------------------------------------------------------- /packages/jsonld-lint/__tests__/__fixtures__/0004-out.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "type": "jsonld-lint-result/term-definition", 4 | "name": "@context", 5 | "isJsonLdKeyword": true, 6 | "documentPosition": { 7 | "startPositionOffset": 4, 8 | "endPositionOffset": 14 9 | } 10 | }, 11 | { 12 | "type": "jsonld-lint-result/term-definition", 13 | "name": "@version", 14 | "isJsonLdKeyword": true, 15 | "documentPosition": { 16 | "startPositionOffset": 22, 17 | "endPositionOffset": 32 18 | } 19 | }, 20 | { 21 | "type": "jsonld-lint-result/syntax-error", 22 | "rule": "jsonld-lint/unexpected-json-value-type", 23 | "message": "Value type for the JSON-LD keyword \"@version\" of \"string\" is invalid, expected type: number", 24 | "documentPosition": { 25 | "startPositionOffset": 34, 26 | "endPositionOffset": 44 27 | }, 28 | "value": "@version" 29 | } 30 | ] 31 | -------------------------------------------------------------------------------- /packages/jsonld-lint/__tests__/__fixtures__/0005-out.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "type": "jsonld-lint-result/term-definition", 4 | "name": "@context", 5 | "isJsonLdKeyword": true, 6 | "documentPosition": { 7 | "startPositionOffset": 4, 8 | "endPositionOffset": 14 9 | } 10 | }, 11 | { 12 | "type": "jsonld-lint-result/term-definition", 13 | "name": "@version", 14 | "isJsonLdKeyword": true, 15 | "documentPosition": { 16 | "startPositionOffset": 22, 17 | "endPositionOffset": 32 18 | } 19 | }, 20 | { 21 | "type": "jsonld-lint-result/syntax-error", 22 | "rule": "jsonld-lint/unexpected-json-value-type", 23 | "message": "Value type for the JSON-LD keyword \"@version\" of \"boolean\" is invalid, expected type: number", 24 | "documentPosition": { 25 | "startPositionOffset": 34, 26 | "endPositionOffset": 39 27 | }, 28 | "value": "@version" 29 | } 30 | ] 31 | -------------------------------------------------------------------------------- /packages/jsonld-lint-cli/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jsonld-lint-cli", 3 | "description": "JSON-LD Linter CLI", 4 | "license": "Apache-2.0", 5 | "homepage": "https://github.com/mattrglobal/jsonld-lint", 6 | "version": "0.4.0", 7 | "main": "lib/index.js", 8 | "bin": { 9 | "jsonld-lint": "./bin/index.js" 10 | }, 11 | "directories": { 12 | "bin": "bin" 13 | }, 14 | "files": [ 15 | "bin" 16 | ], 17 | "repository": { 18 | "type": "git", 19 | "url": "git+https://github.com/mattrglobal/jsonld-lint.git" 20 | }, 21 | "scripts": { 22 | "build": "rm -rf bin/ && tsc --pretty && cp src/index.js bin/index.js" 23 | }, 24 | "devDependencies": { 25 | "@types/jest": "29.5.13", 26 | "@types/node": "17.0.42", 27 | "jest": "29.7.0", 28 | "ts-jest": "29.2.5", 29 | "typescript": "4.3.5" 30 | }, 31 | "dependencies": { 32 | "commander": "6.0.0", 33 | "jsonld-lint": "0.4.0" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ###################### 2 | # Project Specific 3 | ###################### 4 | lib/ 5 | jest_results/ 6 | node_modules/ 7 | .npmrc 8 | out/ 9 | .vscode-test/ 10 | 11 | ###################### 12 | # Visual Studio Code 13 | ###################### 14 | .vscode/ 15 | 16 | ###################### 17 | # Webstorm 18 | ###################### 19 | .idea 20 | 21 | ###################### 22 | # Windows 23 | ###################### 24 | # Windows image file caches 25 | Thumbs.db 26 | 27 | # Folder config file 28 | Desktop.ini 29 | 30 | ###################### 31 | # Mac OSX 32 | ###################### 33 | .DS_Store 34 | 35 | # Thumbnails 36 | ._* 37 | 38 | # Files that might appear on external disk 39 | .Spotlight-V100 40 | .Trashes 41 | 42 | ###################### 43 | # Logs 44 | ###################### 45 | *.log* 46 | 47 | ###################### 48 | # Others 49 | ###################### 50 | *.*~ 51 | *~ 52 | .merge_file* 53 | *.swp 54 | *.swo 55 | **/bin 56 | -------------------------------------------------------------------------------- /packages/jsonld-lint/__tests__/__fixtures__/0007-out.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "type": "jsonld-lint-result/term-definition", 4 | "name": "@context", 5 | "isJsonLdKeyword": true, 6 | "documentPosition": { 7 | "startPositionOffset": 4, 8 | "endPositionOffset": 14 9 | } 10 | }, 11 | { 12 | "type": "jsonld-lint-result/linting-result", 13 | "rule": "jsonld-lint/unrecognized-jsonld-keyword", 14 | "message": "The term \"@notAValidProperty\" matches the convention of a JSON-LD syntax token but is un-recognized", 15 | "value": "@notAValidProperty", 16 | "documentPosition": { 17 | "startPositionOffset": 22, 18 | "endPositionOffset": 42 19 | } 20 | }, 21 | { 22 | "type": "jsonld-lint-result/term-definition", 23 | "name": "@notAValidProperty", 24 | "isJsonLdKeyword": false, 25 | "documentPosition": { 26 | "startPositionOffset": 22, 27 | "endPositionOffset": 42 28 | } 29 | } 30 | ] 31 | -------------------------------------------------------------------------------- /packages/jsonld-lint/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jsonld-lint", 3 | "description": "JSON-LD Linter", 4 | "license": "Apache-2.0", 5 | "homepage": "https://github.com/mattrglobal/jsonld-lint", 6 | "version": "0.4.0", 7 | "main": "lib/index.js", 8 | "directories": { 9 | "lib": "lib" 10 | }, 11 | "files": [ 12 | "lib" 13 | ], 14 | "typings": "lib/index.d.ts", 15 | "repository": { 16 | "type": "git", 17 | "url": "git+https://github.com/mattrglobal/jsonld-lint.git" 18 | }, 19 | "scripts": { 20 | "build": "tsc --pretty", 21 | "test": "jest" 22 | }, 23 | "devDependencies": { 24 | "@types/jest": "29.5.13", 25 | "@types/lru-cache": "5.1.0", 26 | "@types/node": "17.0.42", 27 | "jest": "29.7.0", 28 | "ts-jest": "29.2.5", 29 | "typescript": "4.3.5" 30 | }, 31 | "dependencies": { 32 | "jsonld": "3.3.2", 33 | "lru-cache": "6.0.0", 34 | "vscode-json-languageservice": "3.8.1" 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /packages/jsonld-lint/__tests__/__fixtures__/0009-out.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "type": "jsonld-lint-result/term-definition", 4 | "name": "@context", 5 | "isJsonLdKeyword": true, 6 | "documentPosition": { 7 | "startPositionOffset": 4, 8 | "endPositionOffset": 14 9 | } 10 | }, 11 | { 12 | "type": "jsonld-lint-result/syntax-error", 13 | "rule": "jsonld-lint/duplicate-property-in-json-object", 14 | "message": "Duplicate property of \"id\" encountered", 15 | "value": "id", 16 | "documentPosition": { 17 | "startPositionOffset": 22, 18 | "endPositionOffset": 26 19 | } 20 | }, 21 | { 22 | "type": "jsonld-lint-result/syntax-error", 23 | "rule": "jsonld-lint/duplicate-property-in-json-object", 24 | "message": "Duplicate property of \"id\" encountered", 25 | "value": "id", 26 | "documentPosition": { 27 | "startPositionOffset": 41, 28 | "endPositionOffset": 45 29 | } 30 | } 31 | ] 32 | -------------------------------------------------------------------------------- /packages/jsonld-lint-cli/src/index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* 4 | * Copyright 2020 - MATTR Limited 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | /** 17 | * This file is required as `tsc` does not follow the 18 | * file permission rules of the input when generating an 19 | * output allocating `-rw-r--r--` instead of `-rwxr-xr-x` 20 | * which is required for the file to be executable 21 | */ 22 | 23 | require("./cli"); 24 | -------------------------------------------------------------------------------- /packages/jsonld-lint/__tests__/__fixtures__/0008-out.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "documentPosition": { 4 | "endPositionOffset": 14, 5 | "startPositionOffset": 4 6 | }, 7 | "isJsonLdKeyword": true, 8 | "name": "@context", 9 | "type": "jsonld-lint-result/term-definition" 10 | }, 11 | { 12 | "documentPosition": { 13 | "endPositionOffset": 26, 14 | "startPositionOffset": 22 15 | }, 16 | "message": "Duplicate aliased property of JSON-LD term of \"id\" encountered", 17 | "rule": "jsonld-lint/duplicate-property-in-json-object", 18 | "type": "jsonld-lint-result/syntax-error", 19 | "value": "id" 20 | }, 21 | { 22 | "documentPosition": { 23 | "endPositionOffset": 46, 24 | "startPositionOffset": 41 25 | }, 26 | "message": "Duplicate aliased property of JSON-LD term of \"@id\" encountered", 27 | "rule": "jsonld-lint/duplicate-property-in-json-object", 28 | "type": "jsonld-lint-result/syntax-error", 29 | "value": "@id" 30 | } 31 | ] 32 | -------------------------------------------------------------------------------- /packages/jsonld-lint/__tests__/__fixtures__/0001-out.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "type": "jsonld-lint-result/term-definition", 4 | "name": "@context", 5 | "iri": "https://www.w3.org/TR/json-ld11/#the-context", 6 | "isJsonLdKeyword": true, 7 | "documentPosition": { 8 | "startPositionOffset": 4, 9 | "endPositionOffset": 14 10 | } 11 | }, 12 | { 13 | "type": "jsonld-lint-result/term-definition", 14 | "name": "definedTerm", 15 | "isJsonLdKeyword": false, 16 | "iri": "https://example.com/definedTerm", 17 | "documentPosition": { 18 | "startPositionOffset": 78, 19 | "endPositionOffset": 91 20 | } 21 | }, 22 | { 23 | "type": "jsonld-lint-result/linting-result", 24 | "rule": "jsonld-lint/unmapped-term", 25 | "message": "The term \"undefinedTerm\" is not defined in the document context (unmapped)", 26 | "value": "undefinedTerm", 27 | "documentPosition": { 28 | "startPositionOffset": 103, 29 | "endPositionOffset": 118 30 | } 31 | } 32 | ] 33 | -------------------------------------------------------------------------------- /packages/jsonld-lint-vscode/src/test/suite/index.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import Mocha from "mocha"; 3 | import glob from "glob"; 4 | 5 | export function run(): Promise { 6 | // Create the mocha test 7 | const mocha = new Mocha({ 8 | ui: "tdd", 9 | color: true, 10 | }); 11 | 12 | const testsRoot = path.resolve(__dirname, ".."); 13 | 14 | return new Promise((c, e) => { 15 | glob("**/**.test.js", { cwd: testsRoot }, (err, files) => { 16 | if (err) { 17 | return e(err); 18 | } 19 | 20 | // Add files to the test suite 21 | files.forEach((f) => mocha.addFile(path.resolve(testsRoot, f))); 22 | 23 | try { 24 | // Run the mocha test 25 | mocha.run((failures) => { 26 | if (failures > 0) { 27 | e(new Error(`${failures} tests failed.`)); 28 | } else { 29 | c(); 30 | } 31 | }); 32 | } catch (err) { 33 | console.error(err); 34 | e(err); 35 | } 36 | }); 37 | }); 38 | } 39 | -------------------------------------------------------------------------------- /packages/jsonld-lint-cli/README.md: -------------------------------------------------------------------------------- 1 | ![Mattr logo](../../docs/assets/mattr-black.svg) 2 | 3 | # JSON-LD Lint CLI 4 | 5 | ![npm-version](https://badgen.net/npm/v/jsonld-lint-cli) 6 | ![npm-unstable-version](https://badgen.net/npm/v/jsonld-lint-cli) 7 | ![push-master](https://github.com/mattrglobal/jsonld-lint/workflows/push-master/badge.svg) 8 | ![push-release](https://github.com/mattrglobal/jsonld-lint/workflows/push-release/badge.svg) 9 | 10 | The jsonld-lint engine bundled as a CLI tool 11 | 12 |

13 | 14 | ## Getting started 15 | 16 | With your favorite package manager install 17 | 18 | With [yarn](https://yarnpkg.com/) run 19 | 20 | ``` 21 | yarn add jsonld-lint-cli 22 | ``` 23 | 24 | Or [npm](https://www.npmjs.com/) run 25 | 26 | ``` 27 | npm i -g jsonld-lint-cli 28 | ``` 29 | 30 | Now lint your document 31 | 32 | ``` 33 | jsonld-lint my-jsonld-document.jsonld 34 | ``` 35 | 36 | Or a directory of documents 37 | 38 | ``` 39 | jsonld-lint ./my-directory-of-jsonld-documents 40 | ``` 41 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | 4 | 5 | ## Description 6 | 7 | 8 | 9 | - [ ] Tests for the changes have been added (for bug fixes / features) 10 | - [ ] The commit message(s) follow [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/) 11 | - [ ] Documentation has been added / updated (for bug fixes / features) 12 | - [ ] Changes follow the **[contributing](../CONTRIBUTING.md)** document. 13 | 14 | ## Motivation and Context 15 | 16 | 17 | 18 | ## Does this PR introduce a breaking change? 19 | 20 | - [ ] Yes 21 | - [ ] No 22 | 23 | 24 | 25 | ## Which merge strategy will you use? 26 | 27 | 28 | 29 | - [ ] Squash 30 | - [ ] Rebase (REVIEW COMMITS) 31 | -------------------------------------------------------------------------------- /packages/jsonld-lint/src/types/DocumentPosition.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 - MATTR Limited 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | /** 15 | * Defines an elements position within a document 16 | */ 17 | export interface DocumentPosition { 18 | /** 19 | * A zero based offset position for the start of the term within the JSON document 20 | */ 21 | readonly startPositionOffset: number; 22 | /** 23 | * A zero based offset position for the end of the term within the JSON document 24 | */ 25 | readonly endPositionOffset: number; 26 | } 27 | -------------------------------------------------------------------------------- /packages/jsonld-lint-cli/jest.config.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 - MATTR Limited 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | const pack = require("./package"); 15 | 16 | module.exports = { 17 | preset: "ts-jest", 18 | roots: ["/src", "/__tests__"], 19 | testPathIgnorePatterns: ["/node_modules/", "/output/"], 20 | testRegex: [".spec.ts$"], 21 | moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"], 22 | coveragePathIgnorePatterns: ["/__tests__"], 23 | verbose: true, 24 | name: pack.name, 25 | displayName: pack.name 26 | }; 27 | -------------------------------------------------------------------------------- /packages/jsonld-lint/jest.config.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 - MATTR Limited 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | const pack = require("./package"); 15 | 16 | module.exports = { 17 | preset: "ts-jest", 18 | roots: ["/src", "/__tests__"], 19 | testPathIgnorePatterns: ["/node_modules/", "/output/"], 20 | testRegex: [".spec.ts$"], 21 | moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"], 22 | coveragePathIgnorePatterns: ["/__tests__"], 23 | testTimeout: 30000, 24 | verbose: true, 25 | name: pack.name, 26 | displayName: pack.name 27 | }; 28 | -------------------------------------------------------------------------------- /packages/jsonld-lint/src/types/JsonLdDocumentTermInfo.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 - MATTR Limited 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | /** 15 | * A JSON-LD document term 16 | */ 17 | export interface JsonLdDocumentTermInfo { 18 | /** 19 | * The compacted term 20 | */ 21 | readonly name: string; 22 | /** 23 | * The fully qualified term IRI 24 | */ 25 | readonly iri?: string; 26 | /** 27 | * The value type IRI 28 | */ 29 | readonly valueTypeIri?: string; 30 | /** 31 | * Indicates whether the term is a JSON-LD type 32 | */ 33 | readonly isJsonLdKeyword: boolean; 34 | } 35 | -------------------------------------------------------------------------------- /packages/jsonld-lint/src/types/JsonLdLintOptions.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 - MATTR Limited 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | import { JsonLdDocumentLintRule } from "./JsonLdDocumentLintRule"; 15 | import { ContextResolver } from "./ContextResolver"; 16 | 17 | /** 18 | * Options for linting a JSON-LD document 19 | */ 20 | export interface JsonLdLintOptions { 21 | /** 22 | * The rule set to use for the linting process 23 | */ 24 | readonly lintingRules?: JsonLdDocumentLintRule[]; 25 | /** 26 | * JSON-LD context resolver 27 | */ 28 | readonly contextResolver?: ContextResolver; 29 | } 30 | -------------------------------------------------------------------------------- /.github/workflows/github_backup.yaml: -------------------------------------------------------------------------------- 1 | name: Mirror repository to S3 2 | on: 3 | push: 4 | branches: 5 | - master 6 | jobs: 7 | BackupRepoToS3: 8 | runs-on: ubuntu-latest 9 | permissions: 10 | contents: read 11 | id-token: write 12 | steps: 13 | - name: Checkout 14 | uses: actions/checkout@v4 15 | 16 | - name: Configure aws credentials 17 | uses: aws-actions/configure-aws-credentials@v1 18 | with: 19 | aws-region: ap-southeast-2 20 | role-to-assume: arn:aws:iam::817632051851:role/oidc-github-actions-mattrglobal-global 21 | role-duration-seconds: 900 22 | role-session-name: GithubActions 23 | 24 | - name: Backing up this repo to AWS S3 25 | uses: peter-evans/s3-backup@v1 26 | env: 27 | AWS_REGION: ${{ env.AWS_REGION }} 28 | ACCESS_KEY_ID: ${{ env.AWS_ACCESS_KEY_ID }} 29 | MIRROR_TARGET: mattrglobal-github-backup/jsonld-lint 30 | SECRET_ACCESS_KEY: ${{ env.AWS_SECRET_ACCESS_KEY }} 31 | AWS_SESSION_TOKEN: ${{ env.AWS_SESSION_TOKEN }} 32 | with: 33 | args: --overwrite --remove 34 | -------------------------------------------------------------------------------- /docs/assets/mattr-logo-square.svg: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /packages/jsonld-lint/src/types/JsonLdLintError.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 - MATTR Limited 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | export const JsonLdLintErrorName = "jsonld-lint-error"; 15 | 16 | export enum JsonLdLintErrorType { 17 | ParsingError, 18 | JsonLdDetectionError, 19 | ProcessingError, 20 | JsonLdSyntaxError, 21 | } 22 | 23 | export interface JsonLdLintError { 24 | /** 25 | * Name of the error 26 | */ 27 | readonly name: string; 28 | /** 29 | * Type of the error 30 | */ 31 | readonly type: JsonLdLintErrorType; 32 | /** 33 | * Error message 34 | */ 35 | readonly message?: string; 36 | /** 37 | * Error details 38 | */ 39 | readonly details?: any; 40 | } 41 | -------------------------------------------------------------------------------- /packages/jsonld-lint/src/types/JsonLdDocumentProcessingResult.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 - MATTR Limited 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | /** 15 | * An enumeration of result types 16 | */ 17 | export enum JsonLdDocumentProcessingResultType { 18 | JsonLdSyntaxError = "jsonld-lint-result/syntax-error", 19 | JsonLdLintingResult = "jsonld-lint-result/linting-result", 20 | JsonLdTerm = "jsonld-lint-result/term-definition", 21 | JsonLdTermValue = "jsonld-lint-result/term-value", 22 | } 23 | 24 | /** 25 | * Base Result type from processing a JSON-LD Document 26 | */ 27 | export interface BaseJsonLdDocumentProcessingResult { 28 | /** 29 | * The type of processing result 30 | */ 31 | readonly type: JsonLdDocumentProcessingResultType; 32 | } 33 | -------------------------------------------------------------------------------- /packages/jsonld-lint-vscode/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jsonld-lint-vscode", 3 | "description": "JSON-LD Linter for vs code", 4 | "private": true, 5 | "license": "Apache-2.0", 6 | "version": "0.4.0", 7 | "engines": { 8 | "vscode": "^1.46.1" 9 | }, 10 | "categories": [ 11 | "Other" 12 | ], 13 | "activationEvents": [ 14 | "*" 15 | ], 16 | "main": "./out/index.js", 17 | "contributes": { 18 | "colors": [ 19 | { 20 | "id": "jsonldlint.JsonLdLintResultBackgroundColor", 21 | "description": "Background color style for an issue identified by JSON-LD lint", 22 | "defaults": { 23 | "dark": "#e63333e5", 24 | "light": "#e63333e5", 25 | "highContrast": "#e63333e5" 26 | } 27 | } 28 | ] 29 | }, 30 | "scripts": { 31 | "build": "tsc -p ./", 32 | "watch": "tsc -watch -p ./", 33 | "test:integration": "node ./out/test/runTest.js" 34 | }, 35 | "devDependencies": { 36 | "@types/glob": "7.2.0", 37 | "@types/mocha": "8.0.0", 38 | "@types/node": "17.0.42", 39 | "@types/vscode": "1.68.0", 40 | "eslint": "7.6.0", 41 | "glob": "7.1.6", 42 | "mocha": "8.4.0", 43 | "typescript": "4.3.5", 44 | "vscode-test": "1.4.0" 45 | }, 46 | "dependencies": { 47 | "jsonld-lint": "0.4.0" 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /.github/workflows/push-master.yml: -------------------------------------------------------------------------------- 1 | name: push-master 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | 8 | jobs: 9 | build_test_publish: 10 | name: Build, test, and publish unstable release 11 | runs-on: ubuntu-latest 12 | steps: 13 | - name: Checkout 14 | uses: actions/checkout@v4 15 | with: 16 | # checkout master explicitly as workflow triggered on a tag which results in checkout of detached HEAD 17 | ref: master 18 | # 0 indicates all history, needed for correct unstable version generation (commit count since last release) 19 | fetch-depth: 0 20 | 21 | - name: Setup nodejs 22 | uses: actions/setup-node@v4 23 | with: 24 | node-version: 22.x 25 | registry-url: "https://registry.npmjs.org" 26 | 27 | - name: Install, lint and build 28 | run: | 29 | yarn install --frozen-lockfile 30 | yarn lint 31 | yarn build 32 | 33 | - name: Test (unit) 34 | run: yarn test 35 | 36 | - name: Publish unstable release 37 | env: 38 | NODE_AUTH_TOKEN: ${{ secrets.NPMJS_PUBLIC_TOKEN }} 39 | run: | 40 | git config user.name "Mattr CI" 41 | git config user.email "npmjs_ci_mattr_public@mattr.global" 42 | 43 | yarn publish:unstable 44 | -------------------------------------------------------------------------------- /packages/jsonld-lint/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | # [0.4.0](https://github.com/mattrglobal/jsonld-lint/compare/jsonld-lint@0.3.0...jsonld-lint@0.4.0) (2022-06-22) 7 | 8 | **Note:** Version bump only for package jsonld-lint 9 | 10 | # [0.3.0](https://github.com/mattrglobal/jsonld-lint/compare/jsonld-lint@0.2.0...jsonld-lint@0.3.0) (2020-10-29) 11 | 12 | ### Bug Fixes 13 | 14 | - **jsonld-lint:** minor improvement to linting result formating ([#15](https://github.com/mattrglobal/jsonld-lint/issues/15)) ([b795bd7](https://github.com/mattrglobal/jsonld-lint/commit/b795bd72ddf9e83b36c76bac549cf68b581101f3)) 15 | - **jsonld-lint:** remove problematic rule and cleanup msg output format ([#16](https://github.com/mattrglobal/jsonld-lint/issues/16)) ([e0bb005](https://github.com/mattrglobal/jsonld-lint/commit/e0bb005791534fb9a6ab72ecaea54cf279224c89)) 16 | 17 | # [0.2.0](https://github.com/mattrglobal/jsonld-lint/compare/jsonld-lint@0.1.0...jsonld-lint@0.2.0) (2020-10-09) 18 | 19 | ### Features 20 | 21 | - **jsonld-lint:** empty json property key ([e7ef6cb](https://github.com/mattrglobal/jsonld-lint/commit/e7ef6cbae61d057f285d62d12c81a0e19124b86b)) 22 | 23 | # 0.1.0 (2020-10-08) 24 | 25 | Initial release 26 | -------------------------------------------------------------------------------- /.github/workflows/push-release.yml: -------------------------------------------------------------------------------- 1 | name: push-release 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | 8 | jobs: 9 | build_test_publish: 10 | name: Build, test, and publish stable release 11 | if: "contains(github.event.head_commit.message, 'chore(release): publish')" 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - name: Checkout 16 | uses: actions/checkout@v4 17 | with: 18 | # checkout master explicitly as workflow triggered on a tag which results in checkout of detached HEAD 19 | ref: master 20 | # 0 indicates all history, needed for correct unstable version generation (commit count since last release) 21 | fetch-depth: 0 22 | 23 | - name: Setup nodejs 24 | uses: actions/setup-node@v4 25 | with: 26 | node-version: 22.x 27 | registry-url: "https://registry.npmjs.org" 28 | 29 | - name: Install, lint and build 30 | run: | 31 | yarn install --frozen-lockfile 32 | yarn lint 33 | yarn build 34 | 35 | - name: Test (unit) 36 | run: yarn test 37 | 38 | - name: Publish stable release 39 | env: 40 | NODE_AUTH_TOKEN: ${{ secrets.NPMJS_PUBLIC_TOKEN }} 41 | run: | 42 | git config user.name "Mattr CI" 43 | git config user.email "npmjs_ci_mattr_public@mattr.global" 44 | 45 | yarn publish:release 46 | -------------------------------------------------------------------------------- /packages/jsonld-lint/src/types/JsonLdDocumentContext.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 - MATTR Limited 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | import { JsonLdDocumentTermContext } from "./JsonLdDocumentTermContext"; 15 | 16 | /** 17 | * A map of terms and whether they are protected 18 | */ 19 | export interface ProtectedTerms { 20 | /** 21 | * The term and boolean status on whether 22 | * it is protected 23 | */ 24 | readonly [key: string]: boolean; 25 | } 26 | 27 | /** 28 | * A JSON-LD document context 29 | */ 30 | export interface JsonLdDocumentContext { 31 | /** 32 | * The JSON-LD processing mode 33 | */ 34 | readonly processingMode: string; 35 | /** 36 | * A map of terms and whether they are protected 37 | */ 38 | readonly protected?: ProtectedTerms; 39 | /** 40 | * A map of terms and their inverse term 41 | */ 42 | readonly inverse?: any; 43 | /** 44 | * TODO should validate 45 | */ 46 | readonly mappings?: Map; 47 | } 48 | -------------------------------------------------------------------------------- /packages/jsonld-lint/src/types/JsonLdDocumentTermContext.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 - MATTR Limited 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | /** 15 | * A JSON-LD document term context 16 | */ 17 | export interface JsonLdDocumentTermContext { 18 | /** 19 | * Indicates whether the reverse property applies to this term 20 | */ 21 | readonly reverse: boolean; 22 | /** 23 | * A map of terms and whether they are protected 24 | */ 25 | readonly _termHasColon: boolean; 26 | /** 27 | * Identifier for the term 28 | */ 29 | readonly "@id": string; 30 | /** 31 | * Type for the term 32 | */ 33 | readonly "@type"?: string; 34 | /** 35 | * If the term is a context the value of the context 36 | */ 37 | readonly "@context"?: any; 38 | /** 39 | * Container associated to the term 40 | */ 41 | readonly "@container"?: readonly string[]; 42 | /** 43 | * Indicates whether the term is protected 44 | */ 45 | readonly protected: boolean; 46 | /** 47 | * Indicates whether the term is prefixed 48 | */ 49 | readonly _prefix: boolean; 50 | } 51 | -------------------------------------------------------------------------------- /packages/jsonld-lint/src/types/JsonLdDocumentLintResult.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 - MATTR Limited 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | import { JsonLdDocumentLintRule } from "./JsonLdDocumentLintRule"; 15 | import { DocumentPosition } from "./DocumentPosition"; 16 | import { JsonLdDocumentProcessingResultType } from "./JsonLdDocumentProcessingResult"; 17 | 18 | /** 19 | * Result from linting a JSON-LD Document 20 | */ 21 | export interface JsonLdDocumentLintResult { 22 | /** 23 | * The processing result type for a JSON-LD syntax error 24 | */ 25 | readonly type: JsonLdDocumentProcessingResultType.JsonLdLintingResult; 26 | /** 27 | * The JSON-LD lint rule breached 28 | */ 29 | readonly rule: JsonLdDocumentLintRule; 30 | /** 31 | * The message describing the linting result 32 | */ 33 | readonly message: string; 34 | /** 35 | * Positional information indicating the where the lint 36 | * result applies to 37 | */ 38 | readonly documentPosition: DocumentPosition; 39 | /** 40 | * Value of the JSON key or value the linting rule breach pertains to 41 | */ 42 | readonly value?: any; 43 | } 44 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "root", 3 | "private": true, 4 | "license": "Apache-2.0", 5 | "repository": { 6 | "type": "git", 7 | "url": "git+https://github.com/mattrglobal/jsonld-lint" 8 | }, 9 | "bugs": { 10 | "url": "https://github.com/mattrglobal/jsonld-lint/issues" 11 | }, 12 | "homepage": "https://github.com/mattrglobal/jsonld-lint#readme", 13 | "useWorkspaces": true, 14 | "workspaces": [ 15 | "packages/*" 16 | ], 17 | "scripts": { 18 | "test": "lerna run test", 19 | "build": "lerna run build", 20 | "format": "prettier --write \"**/*.ts\" \"**/*.md\" \"!**/lib/**\"", 21 | "pre-pr": "yarn format && yarn lint:fix && yarn build && yarn test", 22 | "lint": "prettier --check \"**/*.ts\" \"**/*.md\" \"!**/lib/**\" && tslint --project ./tsconfig.json", 23 | "lint:fix": "prettier --check \"**/*.ts\" \"**/*.md\" \"!**/lib/**\" && tslint --project ./tsconfig.json --fix", 24 | "publish:unstable": "lerna publish --canary --dist-tag=unstable --preid=unstable --yes --exact", 25 | "publish:release": "lerna publish from-git --yes", 26 | "version:release": "lerna version minor --yes --exact --no-push", 27 | "prepare": "husky install" 28 | }, 29 | "devDependencies": { 30 | "@commitlint/cli": "17.0.2", 31 | "@commitlint/config-conventional": "17.0.2", 32 | "husky": "8.0.1", 33 | "jest": "29.7.0", 34 | "jest-html-reporters": "3.0.9", 35 | "lerna": "5.1.8", 36 | "prettier": "2.6.2", 37 | "pretty-quick": "3.1.3", 38 | "ts-jest": "29.2.5", 39 | "tslint": "5.20.1", 40 | "tslint-config-prettier": "1.18.0", 41 | "tslint-consistent-codestyle": "1.16.0", 42 | "tslint-immutable": "6.0.1", 43 | "typescript": "4.3.5" 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /packages/jsonld-lint/src/types/JsonLdDocumentTerm.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 - MATTR Limited 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | import { DocumentPosition } from "./DocumentPosition"; 15 | import { 16 | JsonLdDocumentProcessingResultType, 17 | BaseJsonLdDocumentProcessingResult, 18 | } from "./JsonLdDocumentProcessingResult"; 19 | 20 | /** 21 | * A JSON-LD document term 22 | */ 23 | export interface JsonLdDocumentTerm extends BaseJsonLdDocumentProcessingResult { 24 | /** 25 | * The processing result type for a JSON-LD syntax error 26 | */ 27 | readonly type: JsonLdDocumentProcessingResultType.JsonLdTerm; 28 | /** 29 | * The compacted term 30 | */ 31 | readonly name: string; 32 | /** 33 | * Indicates whether the processed term is a JSON-LD syntax token 34 | */ 35 | readonly isJsonLdKeyword: boolean; 36 | /** 37 | * The fully qualified term IRI 38 | */ 39 | readonly iri?: string; 40 | /** 41 | * The value type IRI 42 | */ 43 | readonly valueTypeIri?: string; 44 | /** 45 | * Positional information indicating where the 46 | * term is located within the document 47 | */ 48 | readonly documentPosition: DocumentPosition; 49 | } 50 | -------------------------------------------------------------------------------- /packages/jsonld-lint/src/utilities.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 - MATTR Limited 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | import { 15 | JsonLdLintErrorType, 16 | JsonLdLintError, 17 | JsonLdLintErrorName, 18 | DocumentPosition, 19 | } from "./types"; 20 | 21 | /** 22 | * Converts a document offset to a position 23 | * @param offset positional offset of the element 24 | * @param length length of the element 25 | */ 26 | export const documentOffSetToPosition = ( 27 | offset: Number, 28 | length: number 29 | ): DocumentPosition => { 30 | const startPositionOffset = offset as number; 31 | const endPositionOffset = ((offset as number) + length) as number; 32 | 33 | return { 34 | startPositionOffset, 35 | endPositionOffset, 36 | }; 37 | }; 38 | 39 | /** 40 | * Creates a JSON-LD lint error 41 | * @param type Type of error to create 42 | * @param message Error message 43 | * @param details Error details 44 | */ 45 | export const createJsonLdLintError = ( 46 | type: JsonLdLintErrorType, 47 | message?: string, 48 | details?: any 49 | ): JsonLdLintError => { 50 | return { 51 | name: JsonLdLintErrorName, 52 | type, 53 | message, 54 | details, 55 | }; 56 | }; 57 | -------------------------------------------------------------------------------- /packages/jsonld-lint/src/types/KnownJsonLdTerm.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 - MATTR Limited 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | import { JsonLdObjectType } from "./JsonLdObjectType"; 15 | 16 | /** 17 | * Type declaration for a value validator for a known JSON-LD term 18 | */ 19 | export type ValueValidator = (value: any) => boolean; 20 | 21 | /** 22 | * A known JSON-LD term 23 | */ 24 | export interface KnownJsonLdTerm { 25 | /** 26 | * The term name 27 | */ 28 | readonly name: string; 29 | /** 30 | * The name of an aliased term 31 | * e.g `@id` is an alias is of `id` 32 | */ 33 | readonly aliasTerm?: string; 34 | /** 35 | * The fully qualified term IRI 36 | */ 37 | readonly iri?: string; 38 | /** 39 | * The expected JSON value types 40 | */ 41 | readonly expectedJsonValueTypes?: string[]; 42 | /** 43 | * The expected JSON values 44 | */ 45 | readonly expectedJsonValues?: any[]; 46 | /** 47 | * An array indicating in which JSON-LD terms 48 | */ 49 | readonly validInJsonLdObjectTypes: JsonLdObjectType[]; 50 | /** 51 | * A map of value validators for a known JSON-LD term 52 | */ 53 | readonly valueValidators?: Map; 54 | } 55 | -------------------------------------------------------------------------------- /packages/jsonld-lint/src/types/JsonLdDocumentProcessingContext.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 - MATTR Limited 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | import { JsonLdDocumentTerm } from "./JsonLdDocumentTerm"; 15 | import { JsonLdDocumentContext } from "./JsonLdDocumentContext"; 16 | import { JsonLdObjectType } from "./JsonLdObjectType"; 17 | import { ContextResolver } from "./ContextResolver"; 18 | 19 | /** 20 | * Describes the processing context 21 | */ 22 | export interface JsonLdDocumentProcessingContext { 23 | /** 24 | * The type of JSON-LD object currently being processed 25 | */ 26 | readonly currentJsonLdObjectType?: JsonLdObjectType; 27 | /** 28 | * Document being processed 29 | */ 30 | readonly document: any; 31 | /** 32 | * The JSON-LD Document context for current document being processed 33 | */ 34 | readonly jsonLdDocumentContext?: JsonLdDocumentContext; 35 | /** 36 | * An array of unmapped terms found in the JSON-LD document during initial processing 37 | */ 38 | readonly unmappedTerms?: string[]; 39 | /** 40 | * The current JSON-LD term being processed 41 | */ 42 | readonly currentTerm?: JsonLdDocumentTerm; 43 | /** 44 | * JSON-LD context resolver 45 | */ 46 | readonly contextResolver: ContextResolver; 47 | } 48 | -------------------------------------------------------------------------------- /packages/jsonld-lint/__tests__/lintCompactDocument.spec.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 - MATTR Limited 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | import { process } from "../src"; 15 | import { JsonLdLintErrorType, JsonLdLintErrorName } from "../src/types"; 16 | import { readFile } from "./utilities"; 17 | import { testCases } from "./__fixtures__"; 18 | 19 | const TEST_FIXTURES_DIRECTORY = "__tests__/__fixtures__"; 20 | 21 | describe("lintCompactDocument", () => { 22 | testCases.forEach(({ inputFileName, outputFileName, description }) => { 23 | it(`should successfully ${description}`, async () => { 24 | const inputFile = await readFile(TEST_FIXTURES_DIRECTORY, inputFileName); 25 | const outputFile = await readFile( 26 | TEST_FIXTURES_DIRECTORY, 27 | outputFileName 28 | ); 29 | const result = await process(inputFile); 30 | expect(result).toMatchObject(JSON.parse(outputFile)); 31 | }); 32 | }); 33 | 34 | it("should throw parsing error when invalid JSON supplied", async () => { 35 | await expect(process("this-is-not-json")).rejects.toMatchObject({ 36 | name: JsonLdLintErrorName, 37 | type: JsonLdLintErrorType.ParsingError, 38 | message: "Unable to parse input document as JSON", 39 | }); 40 | }); 41 | }); 42 | -------------------------------------------------------------------------------- /packages/jsonld-lint/src/types/JsonLdObjectType.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 - MATTR Limited 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | /** 15 | * An enumeration of possible object types as per JSON-LD grammar 16 | * 17 | * @see https://www.w3.org/TR/json-ld11/#json-ld-grammar 18 | */ 19 | export enum JsonLdObjectType { 20 | /** 21 | * Node Object 22 | * 23 | * @see https://www.w3.org/TR/json-ld11/#json-ld-grammar 24 | */ 25 | NodeObject = "NodeObject", 26 | /** 27 | * Frame Object 28 | * 29 | * @see https://www.w3.org/TR/json-ld11/#json-ld-grammar 30 | */ 31 | FrameObject = "FrameObject", 32 | /** 33 | * Graph Object 34 | * 35 | * @see https://www.w3.org/TR/json-ld11/#json-ld-grammar 36 | */ 37 | GraphObject = "GraphObject", 38 | /** 39 | * Graph Object 40 | * 41 | * @see https://www.w3.org/TR/json-ld11/#json-ld-grammar 42 | */ 43 | ValueObject = "ValueObject", 44 | /** 45 | * Local Context 46 | * 47 | * @see https://www.w3.org/TR/json-ld11/#context-definitions 48 | */ 49 | LocalContextDefinition = "LocalContextDefinition", 50 | /** 51 | * Expanded Term Definition 52 | * 53 | * @see https://www.w3.org/TR/json-ld11/#expanded-term-definition 54 | */ 55 | ExpandedTermDefinition = "ExpandedTermDefinition", 56 | } 57 | -------------------------------------------------------------------------------- /packages/jsonld-lint/src/types/index.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 - MATTR Limited 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | import { JsonLdDocumentTerm } from "./JsonLdDocumentTerm"; 15 | import { 16 | JsonLdDocumentSyntaxError, 17 | JsonLdDocumentSyntaxErrorRule, 18 | } from "./JsonLdDocumentSyntaxError"; 19 | import { JsonLdDocumentLintResult } from "./JsonLdDocumentLintResult"; 20 | 21 | export { 22 | JsonLdDocumentSyntaxError, 23 | JsonLdDocumentSyntaxErrorRule, 24 | JsonLdDocumentTerm, 25 | JsonLdDocumentLintResult, 26 | }; 27 | 28 | export type JsonLdDocumentProcessingResult = 29 | | JsonLdDocumentTerm 30 | | JsonLdDocumentSyntaxError 31 | | JsonLdDocumentLintResult; 32 | 33 | export { DocumentPosition } from "./DocumentPosition"; 34 | export { 35 | JsonLdLintError, 36 | JsonLdLintErrorName, 37 | JsonLdLintErrorType, 38 | } from "./JsonLdLintError"; 39 | export { JsonLdLintOptions } from "./JsonLdLintOptions"; 40 | export { JsonLdDocumentLintRule } from "./JsonLdDocumentLintRule"; 41 | export { JsonLdDocumentProcessingContext } from "./JsonLdDocumentProcessingContext"; 42 | export { KnownJsonLdTerm, ValueValidator } from "./KnownJsonLdTerm"; 43 | export { JsonLdDocumentProcessingResultType } from "./JsonLdDocumentProcessingResult"; 44 | export { JsonLdObjectType } from "./JsonLdObjectType"; 45 | export { ContextResolver } from "./ContextResolver"; 46 | export { JsonLdDocumentTermInfo } from "./JsonLdDocumentTermInfo"; 47 | export { JsonLdDocumentContext } from "./JsonLdDocumentContext"; 48 | -------------------------------------------------------------------------------- /packages/jsonld-lint-cli/src/cli.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 - MATTR Limited 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | import { lint, processFile, isDirectory } from "./utilities"; 15 | 16 | // tslint:disable: no-console no-var-requires 17 | 18 | const commander = require("commander"); 19 | const packageJson = require("../package.json"); 20 | 21 | const program = new commander.Command(); 22 | 23 | const programBase = program 24 | .version(packageJson.version) 25 | .description("jsonld-lint"); 26 | 27 | programBase 28 | .command("lint", { isDefault: true }) 29 | .arguments("[fileOrDirectory]") 30 | .option("-r, --recursive", "recursive file search", false) 31 | .option( 32 | "-f, --fileExtensionFilter ", 33 | "file extension filter", 34 | ".jsonld" 35 | ) 36 | .action(async (_: any, cmd?: any) => { 37 | if (!cmd?.args[0]) { 38 | programBase.help(); 39 | process.exit(0); 40 | } 41 | if (await lint(cmd?.args[0], cmd.recursive, cmd.fileExtensionFilter)) { 42 | process.exit(1); 43 | } 44 | process.exit(0); 45 | }); 46 | 47 | programBase 48 | .command("process") 49 | .arguments("[file]") 50 | .action(async (file?: string) => { 51 | if (!file) { 52 | programBase.help(); 53 | process.exit(0); 54 | } 55 | if (isDirectory(file)) { 56 | console.log("Supplied parameter is a directory not a file"); 57 | process.exit(0); 58 | } 59 | if (await processFile(file)) { 60 | process.exit(1); 61 | } 62 | process.exit(0); 63 | }); 64 | 65 | programBase.parse(process.argv); 66 | 67 | if (!programBase.args.length) { 68 | programBase.help(); 69 | } 70 | -------------------------------------------------------------------------------- /packages/jsonld-lint/__tests__/utilities.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 - MATTR Limited 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | import { promises } from "fs"; 15 | import * as path from "path"; 16 | 17 | export const getTestsFixtures = async ( 18 | directory: string, 19 | filter: string 20 | ): Promise => { 21 | const directoryPath = path.join(process.env.PWD as string, directory); 22 | let stat = await promises.lstat(directoryPath); 23 | if (!stat.isDirectory()) { 24 | return []; 25 | } 26 | const files = await getFilesFromDirectory(directory, filter); 27 | return files 28 | .map((item) => item.substring(0, 4)) 29 | .filter((value, index, self) => { 30 | return self.indexOf(value) === index; 31 | }); 32 | }; 33 | 34 | export const readFile = async ( 35 | directory: string, 36 | file: string 37 | ): Promise => { 38 | const directoryPath = path.join(process.env.PWD as string, directory); 39 | const filePath = path.join(directoryPath, file); 40 | return (await promises.readFile(filePath)).toString(); 41 | }; 42 | 43 | export const getFilesFromDirectory = async ( 44 | directory: string, 45 | filter: string 46 | ): Promise => { 47 | let matchedFiles: string[] = []; 48 | let files = await promises.readdir(directory); 49 | for (let i = 0; i < files.length; i++) { 50 | let filename = path.join(directory, files[i]); 51 | let stat = await promises.lstat(filename); 52 | if (stat.isDirectory()) { 53 | continue; 54 | } else if ( 55 | filename.indexOf(filter) >= 0 && 56 | !matchedFiles.includes(filename) 57 | ) { 58 | matchedFiles.push(files[i]); 59 | } 60 | } 61 | return matchedFiles; 62 | }; 63 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![MATTR](./docs/assets/mattr-logo-square.svg)](https://github.com/mattrglobal) 2 | 3 | # JSON-LD Lint 4 | 5 | ![push-master](https://github.com/mattrglobal/jsonld-lint/workflows/push-master/badge.svg) 6 | ![push-release](https://github.com/mattrglobal/jsonld-lint/workflows/push-release/badge.svg) 7 | 8 | This repository is home to a set of packages designed to [lint](<"https://en.wikipedia.org/wiki/Lint_(software)">) [JSON-LD](https://www.w3.org/TR/json-ld11/) documents. 9 | 10 | These include 11 | 12 | ### [JSON-LD Lint cli](./packages/jsonld-lint-cli/README.md) 13 | 14 | A CLI tool for linting/processing JSON-LD documents 15 | 16 |

17 | 18 | ### [JSON-LD Lint VS-Code extension](./packages/jsonld-lint-vscode/README.md) 19 | 20 | _Coming soon_ 21 | 22 | An extension that brings the JSON-LD lint smarts to the popular IDE [VS-Code](https://code.visualstudio.com/) 23 | 24 |

25 | 26 | ### [JSON-LD Lint Core](./packages/jsonld-lint/README.md) 27 | 28 | The core linting and processing engine for JSON-LD documents 29 | 30 | ## Built with 31 | 32 | - [Typescript](https://www.typescriptlang.org/) 33 | - [Lerna](https://lerna.js.org/) 34 | 35 | ## Getting started as a Contributor 36 | 37 | ### Prerequisites 38 | 39 | - [Yarn](https://yarnpkg.com/) 40 | 41 | ### Installation 42 | 43 | With [Yarn](https://yarnpkg.com/) run: 44 | 45 | ``` 46 | yarn install --frozen-lockfile 47 | yarn build 48 | ``` 49 | 50 | ### Testing 51 | 52 | To run all tests across all packages run: 53 | 54 | ``` 55 | yarn test 56 | ``` 57 | 58 | ### Contributing 59 | 60 | Read our [contributing guide](./CONTRIBUTING.md) to learn about our development process. 61 | 62 | ## Release Process 63 | 64 | A description of the release process and how to create a release can be found [here](./docs/RELEASE.md). 65 | 66 | --- 67 | 68 |

Copyright © MATTR Limited. Some rights reserved.
“MATTR” is a trademark of MATTR Limited, registered in New Zealand and other countries.

69 | -------------------------------------------------------------------------------- /packages/jsonld-lint/src/types/JsonLdDocumentSyntaxError.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 - MATTR Limited 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | import { DocumentPosition } from "./DocumentPosition"; 15 | import { 16 | BaseJsonLdDocumentProcessingResult, 17 | JsonLdDocumentProcessingResultType, 18 | } from "./JsonLdDocumentProcessingResult"; 19 | 20 | /** 21 | * JSON-LD Document Syntax error type 22 | */ 23 | export enum JsonLdDocumentSyntaxErrorRule { 24 | UnexpectedJsonLdKeywordValueType = "jsonld-lint/unexpected-json-value-type", 25 | UnexpectedJsonLdKeywordValue = "jsonld-lint/unexpected-json-value", 26 | UnexpectedUseOfJsonLdKeyword = "jsonld-lint/unexpected-use-of-jsonld-keyword", 27 | DuplicatePropertyInJsonObject = "jsonld-lint/duplicate-property-in-json-object", 28 | DuplicateAliasPropertyInJsonObject = "jsonld-lint/duplicate-property-in-json-object", 29 | InvalidJsonLdKeywordAsTermValue = "jsonld-lint/invalid-jsonld-keyword-as-term-value", 30 | EmptyJsonPropertyKey = "jsonld-lint/empty-json-property-key", 31 | } 32 | 33 | export interface JsonLdDocumentSyntaxError 34 | extends BaseJsonLdDocumentProcessingResult { 35 | /** 36 | * The processing result type for a JSON-LD syntax error 37 | */ 38 | readonly type: JsonLdDocumentProcessingResultType.JsonLdSyntaxError; 39 | /** 40 | * The JSON-LD syntax error type 41 | */ 42 | readonly rule: JsonLdDocumentSyntaxErrorRule; 43 | /** 44 | * Positional information indicating the where the lint 45 | * result applies to 46 | */ 47 | readonly documentPosition: DocumentPosition; 48 | /** 49 | * The message for the syntax error 50 | */ 51 | readonly message: string; 52 | /** 53 | * Value of the JSON key or value the linting rule breach pertains to 54 | */ 55 | readonly value?: any; 56 | } 57 | -------------------------------------------------------------------------------- /docs/RELEASE.md: -------------------------------------------------------------------------------- 1 | # Stable Releases 2 | 3 | To create a stable release follow the following steps 4 | 5 | 1. Checkout the head of master `git checkout master && git pull` 6 | 2. Create a new release branch from master called `release` 7 | 3. Install the dependencies `yarn install --frozen-lockfile` 8 | 4. Build the package `yarn build` 9 | 5. Test the package `yarn test` 10 | 6. Run `yarn version:release`, note by default this will do a minor package release as we are pre the `1.0.0` release 11 | 7. Observe the correctly incremented change to the `package.json` and the new entry in `CHANGELOG.md` along with the 12 | newly created commit 13 | 8. Push the release branch including the newly created tags `git push origin release --tags` 14 | 9. Open a pull request for the release, once approvals have been sought, merge the pull request using rebase, 15 | preserving the commit message as `chore(release): publish [skip ci]` 16 | 10. Observe the triggering of the `/.github/workflows/push-release.yaml` 17 | 18 | **Note** It is important that rebase is used as the strategy for merging a release pull request as this preserves the created release tag. 19 | 20 | The resulting release will publish the new package to NPM and the resulting binaries to github packages. 21 | 22 | # Unstable Releases 23 | 24 | An unstable release is triggered on every commit to master, where the `/.github/workflows/push-master.yaml` is run. 25 | 26 | The releases have the following version syntax 27 | `-unstable.` 28 | 29 | **Note** The `/.github/workflows/push-master.yaml` will skip if the commit message includes `[skip ci]` 30 | 31 | **Note** To skip the automatic release of a new unstable version append `[skip ci]` to the end of the commit message 32 | that is merged into master. 33 | 34 | # Unstable Releases 35 | 36 | An unstable release is triggered on every commit to master, where the `/.github/workflows/push-master.yaml` is run. 37 | 38 | The releases have the following version syntax 39 | `-unstable.` 40 | 41 | **Note** The `/.github/workflows/push-master.yaml` will skip if the commit message includes `[skip ci]` 42 | 43 | **Note** To skip the automatic release of a new unstable version append `[skip ci]` to the end of the commit message 44 | that is merged into master. 45 | -------------------------------------------------------------------------------- /packages/jsonld-lint/__tests__/__fixtures__/index.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 - MATTR Limited 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | /** 15 | * An array of test cases 16 | */ 17 | export const testCases = [ 18 | { 19 | inputFileName: "0001-in.json", 20 | outputFileName: "0001-out.json", 21 | description: "detect un-mapped terms", 22 | }, 23 | { 24 | inputFileName: "0002-in.json", 25 | outputFileName: "0002-out.json", 26 | description: "detect boolean value type for @context as syntax error", 27 | }, 28 | { 29 | inputFileName: "0003-in.json", 30 | outputFileName: "0003-out.json", 31 | description: "detect numeric value type for @context as syntax error", 32 | }, 33 | { 34 | inputFileName: "0004-in.json", 35 | outputFileName: "0004-out.json", 36 | description: "detect string value type for @version as syntax error", 37 | }, 38 | { 39 | inputFileName: "0005-in.json", 40 | outputFileName: "0005-out.json", 41 | description: "detect boolean value type for @version as syntax error", 42 | }, 43 | { 44 | inputFileName: "0006-in.json", 45 | outputFileName: "0006-out.json", 46 | description: 47 | "detect un-expected numeric value type for @version as syntax error", 48 | }, 49 | { 50 | inputFileName: "0007-in.json", 51 | outputFileName: "0007-out.json", 52 | description: 53 | "detect property matching JSON-LD keyword syntax that is not a known keyword", 54 | }, 55 | { 56 | inputFileName: "0008-in.json", 57 | outputFileName: "0008-out.json", 58 | description: 59 | "detect duplicate aliased properties in object as syntax error", 60 | }, 61 | { 62 | inputFileName: "0009-in.json", 63 | outputFileName: "0009-out.json", 64 | description: "detect duplicate properties in object as syntax error", 65 | }, 66 | { 67 | inputFileName: "0010-in.json", 68 | outputFileName: "0010-out.json", 69 | description: "detect term thats an empty string", 70 | }, 71 | { 72 | inputFileName: "0011-in.json", 73 | outputFileName: "0011-out.json", 74 | description: "detect term with value of syntax token other than @type", 75 | }, 76 | ]; 77 | -------------------------------------------------------------------------------- /docs/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | We use several pieces of technology in this repository to streamline the release process whilst maintaining high code 4 | quality. 5 | 6 | ## Pre pull request checklist 7 | 8 | Below is a brief checklist prior to submitting or updating a pull request 9 | 10 | 1. Running `yarn pre-pr` passes. 11 | 2. Commit messages conform to the below conventions. 12 | 3. The pull request description fills in the relevant fields provided by the template. 13 | 14 | ## Commit messages 15 | 16 | A well formed commit message communicates context about a change. A diff will tell you what changed. A well cared for 17 | commit log is a beautiful and useful thing. 18 | 19 | What may be a hassle at first soon becomes habit, and eventually a source of pride and productivity for all 20 | involved. From reviews to maintenance it's a powerful tool. Understanding why something happened months or years ago 21 | becomes not only possible but efficient. 22 | 23 | We rely on consistent commit messages as we use 24 | [conventional-changelog](https://github.com/conventional-changelog/conventional-changelog) which automatically generates 25 | the changelog diff based on the commit messages 26 | 27 | We enforce well formed commit messages with pre-commit hooks using [husky](https://github.com/typicode/husky). 28 | 29 | The following guidelines are based on the angular 30 | team's [contribution guide](https://github.com/angular/angular/blob/22b96b9/CONTRIBUTING.md#-commit-message-guidelines). 31 | Checkout [commitizen](https://www.npmjs.com/package/commitizen) and [commitlint.io](https://commitlint.io/) for 32 | assistance. 33 | 34 | ``` 35 | (): 36 | 37 | 38 | 39 |