Skip to content

Commit

Permalink
add-linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie Lynch committed Nov 19, 2020
1 parent 62df78e commit b2525ec
Show file tree
Hide file tree
Showing 11 changed files with 1,034 additions and 37 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
.eslintrc.js
jest.config.js
.vscode/*
20 changes: 20 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = {
env: {
browser: true,
es2021: true,
},
extends: "@guardian/eslint-config-typescript",
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaVersion: 12,
tsconfigRootDir: __dirname,
project: ["./tsconfig.eslint.json"],
},
plugins: ["@typescript-eslint"],
rules: {
"@typescript-eslint/no-inferrable-types": 0,
"import/no-namespace": 2,
},
root: true,
ignorePatterns: ["**/*.js", "node_modules"],
};
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"printWidth": 120
}
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"files.watcherExclude": {
"**/target": true
}
}
11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,25 @@
"types": "src/index.d.ts",
"scripts": {
"build": "tsc",
"lint": "eslint src test --ext .ts",
"format": "prettier --write \"(src|test)/**/*.ts\"",
"watch": "tsc -w",
"test": "jest"
},
"devDependencies": {
"@aws-cdk/assert": "1.74.0",
"@guardian/eslint-config-typescript": "^0.4.1",
"@types/jest": "^26.0.10",
"@types/node": "10.17.27",
"@typescript-eslint/eslint-plugin": "^4.8.1",
"@typescript-eslint/parser": "^4.8.1",
"eslint": "^7.13.0",
"eslint-config-prettier": "^6.15.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-prettier": "^3.1.4",
"jest": "^26.4.2",
"prettier": "^2.1.2",
"ts-jest": "^26.2.0",
"typescript": "~3.9.7"
},
Expand Down
9 changes: 4 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import * as cdk from '@aws-cdk/core';
import { Construct } from "@aws-cdk/core";

export interface CdkProps {
// Define construct properties here
name?: string;
}

export class Cdk extends cdk.Construct {

constructor(scope: cdk.Construct, id: string, props: CdkProps = {}) {
export class Cdk extends Construct {
constructor(scope: Construct, id: string, props: CdkProps = {}) {
super(scope, id);

// Define construct contents here
Expand Down
18 changes: 9 additions & 9 deletions test/cdk.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { expect as expectCDK, countResources } from '@aws-cdk/assert';
import * as cdk from '@aws-cdk/core';
import * as Cdk from '../src/index';
import { countResources, expect as expectCDK } from "@aws-cdk/assert";
import { App, Stack } from "@aws-cdk/core";
import { Cdk as Cdk_Cdk } from "../src/index";

/*
* Example test
* Example test
*/
test('SNS Topic Created', () => {
const app = new cdk.App();
const stack = new cdk.Stack(app, "TestStack");
test("SNS Topic Created", () => {
const app = new App();
const stack = new Stack(app, "TestStack");
// WHEN
new Cdk.Cdk(stack, 'MyTestConstruct');
new Cdk_Cdk(stack, "MyTestConstruct");
// THEN
expectCDK(stack).to(countResources("AWS::SNS::Topic",0));
expectCDK(stack).to(countResources("AWS::SNS::Topic", 0));
});
10 changes: 10 additions & 0 deletions tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"include": [
"src/**/*",
"test/**/*"
],
"exclude": [
"node_modules"
]
}
23 changes: 19 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
{
"ts-node": {
"compilerOptions": {
"module": "CommonJS"
}
},
"compilerOptions": {
"target":"ES2018",
"module": "commonjs",
"target": "ES2018",
"module": "esnext",
"moduleResolution": "node",
"lib": ["es2018"],
"declaration": true,
"strict": true,
Expand All @@ -16,8 +22,17 @@
"inlineSourceMap": true,
"inlineSources": true,
"experimentalDecorators": true,
"strictPropertyInitialization":false,
"strictPropertyInitialization": false,
"typeRoots": ["./node_modules/@types"],
"outDir": "dist"
}
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules",
"test",
"src/**/*.test.ts",
"src/**/__snapshots__/**"
]
}
Loading

0 comments on commit b2525ec

Please sign in to comment.