Skip to content

Commit b05130d

Browse files
Merge branch 'VSC-574-ha_initial_commit2' into 'master'
VSC-574 Initial commit Closes VSC-574 See merge request ide/vscode/iar-vsc-common-testutils!2
2 parents fcd47c5 + ee56b79 commit b05130d

13 files changed

Lines changed: 3854 additions & 0 deletions

File tree

.github/workflows/build.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: build
2+
on: [push, workflow_dispatch]
3+
jobs:
4+
build:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- uses: actions/checkout@v3
8+
- uses: actions/setup-node@v3
9+
with:
10+
node-version: 'lts/*'
11+
- run: npm install
12+
- run: npm run lint
13+
- run: npm run prepare

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
dist/

.husky/pre-commit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
node .husky/pre-commit.js

.husky/pre-commit.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/// -----------------------------
2+
// This hook forces all source files in the repository to have the MPL license header at the start of the file.
3+
/// -----------------------------
4+
5+
const { readFileSync } = require("fs");
6+
const { exit } = require("process");
7+
var proc = require('child_process');
8+
9+
function runAndGetStdout(command, callback) {
10+
proc.exec(command, function(error, stdout, stderr) {
11+
callback(stdout);
12+
});
13+
};
14+
15+
const MPLv2_header = `/* This Source Code Form is subject to the terms of the Mozilla Public
16+
* License, v. 2.0. If a copy of the MPL was not distributed with this
17+
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */`
18+
19+
runAndGetStdout("git diff --cached --name-only --diff-filter=ACMR", function(changedFiles) {
20+
const filesArray = changedFiles.trim().split("\n");
21+
// Check that all typescript files have the mpl preamble
22+
const res = filesArray.filter(file => file.endsWith(".ts"))
23+
.map(file => {
24+
const contents = readFileSync(file).toString().replace(/\r\n/g, "\n");
25+
if (!contents.startsWith(MPLv2_header)) {
26+
console.log("Missing or malformed MPLv2 license header in file: " + file);
27+
return false;
28+
}
29+
return true;
30+
});
31+
if (!res.every(v => v)) {
32+
exit(1);
33+
}
34+
});

.vscode/tasks.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"type": "npm",
6+
"script": "watch",
7+
"group": "build",
8+
"problemMatcher": ["$tsc-watch"],
9+
"label": "npm: watch",
10+
"detail": "tsc -p . --watch"
11+
}
12+
]
13+
}

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# iar-vsc-common-testutils
2+
3+
This package contains testing- and development code that is shared between IAR VS Code extensions.
4+
5+
This package is not meant to be published to a package registry; rather, it should be used by adding a `package.json`
6+
dependency on this repository:
7+
```json
8+
"dependencies": {
9+
...
10+
"iar-vsc-common-testutils": "git@github.com:IARSystems/iar-vsc-common-testutils.git#<tag>"
11+
}
12+
```
13+
The typescript source code is transpiled on installation.
14+
15+
For development, it is practical to use a local version of this repository. Simply clone this repository next to the extension repositories. Then, in the extension directory, run:
16+
```sh
17+
npm link <path-to>/iar-vsc-common-testutils
18+
```
19+
The link stays active until you next run `npm install` or `npm unlink`
20+
21+
To use your changes in the extensions, commit your changes, then create and push a tag:
22+
```sh
23+
git tag v1.1.1
24+
git push origin tag v1.1.1
25+
```
26+
27+
In the extension(s) `package.json` file, update the dependency to the new tag.
28+
29+
```json
30+
"dependencies": {
31+
...
32+
"iar-vsc-common-testutils": "git@github.com:IARSystems/iar-vsc-common-testutils.git#v1.1.1"
33+
}
34+
```
35+

eslint.config.mjs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// @ts-check
2+
import eslint from "@eslint/js";
3+
import tseslint from "typescript-eslint";
4+
import globals from "globals";
5+
6+
export default tseslint.config(
7+
{
8+
ignores: ["dist/**"],
9+
},
10+
{
11+
extends: [
12+
eslint.configs.recommended,
13+
...tseslint.configs.recommended,
14+
],
15+
files: ["**/*.ts"],
16+
languageOptions: {
17+
globals: globals.node,
18+
parserOptions: {
19+
project: ["./tsconfig.json"],
20+
},
21+
},
22+
rules: {
23+
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }], // Same as in tsconfig. Allow such vars if they start with an underscore.
24+
"require-await": "error", // Helps catch missing awaits
25+
"strict": "error", // Disallows use of e.g. reserved keywords
26+
"prefer-promise-reject-errors": "error", // Throwing real Errors helps traceability
27+
"@typescript-eslint/no-namespace": "off",
28+
"@typescript-eslint/prefer-readonly": "error",
29+
"@typescript-eslint/consistent-type-definitions": "error", // Prefer 'interface' over 'type'
30+
"@typescript-eslint/no-non-null-assertion": "warn",
31+
"no-empty": "off", // Empty catch blocks can be useful
32+
"no-inner-declarations": "off", // Seems to break when using TS namespaces
33+
"eqeqeq": "error", // == can be obscure/unintuitive, so use ===
34+
"@typescript-eslint/no-deprecated": "warn",
35+
// CODE FORMATTING =================
36+
"semi": "warn",
37+
"camelcase": "warn",
38+
"indent": ["warn", 4],
39+
"space-before-blocks": "warn",
40+
"keyword-spacing": "warn",
41+
"space-before-function-paren": ["warn", "never"],
42+
"dot-location": "warn",
43+
"quotes": ["warn", "double", { "allowTemplateLiterals": true }], // Disallows single quote strings
44+
"comma-spacing": "warn",
45+
"brace-style": "warn",
46+
"no-trailing-spaces": "warn",
47+
},
48+
},
49+
);

0 commit comments

Comments
 (0)