Skip to content
This repository has been archived by the owner on Jun 15, 2021. It is now read-only.

Commit

Permalink
feat: added tsc, tslint, prettier, and a test source file
Browse files Browse the repository at this point in the history
  • Loading branch information
OmarTawfik committed Mar 6, 2019
1 parent 76a96f9 commit 4b92be1
Show file tree
Hide file tree
Showing 8 changed files with 413 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Dependencies
node_modules/
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"printWidth": 120,
"proseWrap": "always"
"proseWrap": "always",
"trailingComma": "all"
}
14 changes: 14 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "workflow-parser-js",
"version": "1.0.0",
"description": "A fast compact parser for GitHub workflows.",
"repository": "https://github.com/OmarTawfik/workflow-parser-js",
"author": "Omar Tawfik <[email protected]>",
"license": "MIT",
"devDependencies": {
"prettier": "1.16.4",
"tslint": "^5.12.1",
"tslint-config-prettier": "1.18.0",
"typescript": "3.3.3"
}
}
19 changes: 19 additions & 0 deletions src/compilation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*!
* Copyright 2019 Omar Tawfik. Please see LICENSE file at the root of this repository.
*/

import { TokenType } from "./scanning/tokens";

export class Compilation {
public static create(text: string): Compilation {
if ((text as unknown) === TokenType.Missing) {
throw new Error("testing infrastructure");
}

return {
member: 1,
};
}

public readonly member = 1;
}
52 changes: 52 additions & 0 deletions src/scanning/tokens.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*!
* Copyright 2019 Omar Tawfik. Please see LICENSE file at the root of this repository.
*/

export const enum TokenType {
// Top-level keywords
VersionKeyword = 1,
WorkflowKeyword = 2,
ActionKeyword = 3,

// Bottom-level keywords
OnKeyword = 4,
ResolvesKeyword = 5,
UsesKeyword = 6,
NeedsKeyword = 7,
RunsKeyword = 8,
ArgsKeyword = 9,
EnvKeyword = 10,
SecretsKeyword = 11,

// Punctuators
Equal = 12,
Comma = 13,

// Brackets
LeftCurlyBracket = 14,
RightCurlyBracket = 15,
LeftSquareBracket = 16,
RightSquareBracket = 17,

// Misc
Identifier = 18,
Comment = 19,

// Literals
IntegerLiteral = 20,
StringLiteral = 21,

// Generated
Missing = 22,
Unrecognized = 23,
}

export interface Token {
readonly length: number;
readonly position: number;
readonly type: TokenType;
}

export namespace TokenUtils {
export const getContents = (text: string, token: Token): string => text.substr(token.position, token.length);
}
21 changes: 21 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"compilerOptions": {
// Compilation options
"target": "es2015",
"module": "commonjs",
"moduleResolution": "node",
"typeRoots": ["./types"],

// Output files
"declaration": true,
"sourceMap": true,
"inlineSources": true,

// Diagnostics
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
}
}
22 changes: 22 additions & 0 deletions tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"defaultSeverity": "error",
"extends": ["tslint:all", "tslint-config-prettier"],
"rules": {
"ban": [
true,
{ "name": ["eval"], "message": "eval() is not type-safe." },
{ "name": ["*", "forEach"], "message": "Use a regular for loop instead." }
],
"completed-docs": false,
"file-header": [
true,
"Copyright 2019 Omar Tawfik\\. Please see LICENSE file at the root of this repository\\.\\n",
"Copyright 2019 Omar Tawfik. Please see LICENSE file at the root of this repository."
],
"interface-name": false,
"no-invalid-this": [true, "check-function-in-method"],
"no-namespace": false,
"typedef": false,
"typeof-compare": true
}
}
Loading

0 comments on commit 4b92be1

Please sign in to comment.