-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Vasek - Tom C <[email protected]>
- Loading branch information
Showing
11 changed files
with
215 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
"folders": [ | ||
{ | ||
"path": "" | ||
}, | ||
{ | ||
"path": "dagger" | ||
}, | ||
{ | ||
"path": "ci" | ||
}, | ||
{ | ||
"path": "golang" | ||
}, | ||
{ | ||
"path": "golangci-lint" | ||
}, | ||
{ | ||
"path": "launcher" | ||
}, | ||
{ | ||
"path": "minio" | ||
}, | ||
{ | ||
"path": "node" | ||
}, | ||
{ | ||
"path": "postgres" | ||
}, | ||
{ | ||
"path": "redis" | ||
}, | ||
{ | ||
"path": "redis-shell" | ||
}, | ||
{ | ||
"path": "rust" | ||
}, | ||
{ | ||
"path": "eslint" | ||
}, | ||
], | ||
"settings": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/sdk/** linguist-generated |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/sdk | ||
/testdata |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Eslint module | ||
|
||
A Typescript linter module for standalone typescript files and Node projects. | ||
|
||
## Usage | ||
|
||
:bulb: If the given files have no `package.json`, `eslintrc` config, or `tsconfig.json`, a default | ||
one will be plugged into the container. | ||
|
||
### Open a shell inside the linter container | ||
|
||
```shell | ||
dagger -m github.com/quartz-technology/daggerverse/eslint --files=<path> call container terminal | ||
``` | ||
|
||
:bulb: It's a practical way to test the module / debug any issue that may happen inside the container. | ||
|
||
### Run the linter on Typescript files | ||
|
||
```shell | ||
dagger -m github.com/quartz-technology/daggerverse/eslint --files=<path> call run stdout | ||
``` | ||
|
||
Made with ❤️ by Quartz. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "eslint", | ||
"sdk": "typescript", | ||
"engineVersion": "v0.9.9" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"dependencies": { | ||
"typescript": "^5.3.2" | ||
}, | ||
"devDependencies": { | ||
"@dagger.io/dagger": "./sdk" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module.exports = { | ||
env: { | ||
node: true | ||
}, | ||
extends: [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/recommended", | ||
], | ||
parser: "@typescript-eslint/parser", | ||
plugins: ["@typescript-eslint"], | ||
root: true, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "app", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"@typescript-eslint/eslint-plugin": "^6.21.0", | ||
"eslint": "^8.56.0", | ||
"eslint-config-standard-with-typescript": "^43.0.1", | ||
"eslint-plugin-import": "^2.29.1", | ||
"eslint-plugin-n": "^16.6.2", | ||
"eslint-plugin-promise": "^6.1.1", | ||
"typescript": "^5.3.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"include": ["**/*.ts"], | ||
"compilerOptions": { | ||
"target": "ES2022", | ||
"moduleResolution": "Node", | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { dag, Container, Directory, object, func, field } from '@dagger.io/dagger'; | ||
|
||
@object() | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
class Eslint { | ||
/** | ||
* The version of eslint to use (default to: 8.56.0). | ||
*/ | ||
@field() | ||
version = "8.56.0" | ||
|
||
/** | ||
* The version of node to use (default to: 21-alpine3.18). | ||
*/ | ||
@field() | ||
nodeVersion = "21-alpine3.18" | ||
|
||
/** | ||
* The files to lint. | ||
*/ | ||
@field() | ||
files: Directory | ||
|
||
/* | ||
* Default configuration files . | ||
*/ | ||
defaultConfig = dag.currentModule().source().directory("src/default-config") | ||
|
||
constructor(files: Directory, version?: string, nodeVersion?: string) { | ||
this.version = version ?? this.version | ||
this.nodeVersion = nodeVersion ?? this.nodeVersion | ||
this.files = files ?? this.files | ||
} | ||
|
||
/** | ||
* Return a container with eslint installed in it. | ||
* | ||
* Example usage: `dagger --files=. call container terminal` | ||
*/ | ||
@func() | ||
async container(): Promise<Container> { | ||
let ctr = dag | ||
.container() | ||
.from(`node:${this.nodeVersion}`) | ||
.withExec(["npm", "install", "-g", `eslint@${this.version}`]) | ||
.withMountedDirectory("/app", this.files) | ||
.withWorkdir("/app") | ||
|
||
// Check if there's an existing project configuration | ||
// and add missing files if they are missing | ||
const files = await ctr.directory(".").entries() | ||
if (!files.find((f) => f === "package.json")) { | ||
ctr = ctr.withFile("package.json", this.defaultConfig.file("package.json")) | ||
} | ||
|
||
if (!files.find((f) => /\.eslintrc\.(js|json|cjs)$/.test(f))) { | ||
ctr = ctr.withFile(".eslintrc.js", this.defaultConfig.file(".eslintrc.js")) | ||
} | ||
|
||
if (!files.find((f) => f === "tsconfig.json")) { | ||
ctr = ctr.withFile("tsconfig.json", this.defaultConfig.file("tsconfig.json")) | ||
} | ||
|
||
return ctr | ||
.withExec(["npm", "install"]) | ||
.withEntrypoint(["eslint"]) | ||
.withDefaultTerminalCmd(["/bin/sh"]) | ||
} | ||
|
||
/** | ||
* Lint the files. | ||
* | ||
* Example usage: `dagger --files=. call run stdout` | ||
*/ | ||
@func() | ||
async run(...args: string[]): Promise<Container> { | ||
return (await this.container()) | ||
.withExec([".", ...args]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2022", | ||
"moduleResolution": "Node", | ||
"experimentalDecorators": true, | ||
"paths": { | ||
"@dagger.io/dagger": ["./sdk"] | ||
} | ||
} | ||
} |