Skip to content

Commit

Permalink
Plugins (#12)
Browse files Browse the repository at this point in the history
* style(plugins): moving plugins

* ci(packages): add package tests to test workflow

Including testing of packages (if they declare tests) to the test workflow

* ci(ci): remove chore

* ci(build): adds tests to build

---------

Co-authored-by: Jake Lauer <[email protected]>
  • Loading branch information
jakelauer and Jake Lauer authored May 27, 2024
1 parent 25f12bd commit 915a191
Show file tree
Hide file tree
Showing 20 changed files with 199 additions and 346 deletions.
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ node_modules
.husky
*.d.ts
!.examples
packages/publisher/**/*
packages/gpt-zip/**/*
9 changes: 7 additions & 2 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
module.exports = {
parser: "@typescript-eslint/parser",
ignorePatterns: ["*.js"],
//ignorePatterns: ["*.js"],
parserOptions: {
project: ["./**/tsconfig.json", "./.examples/**/tsconfig.json"],
project: [
"./tsconfig.json",
"./packages/eslint-plugin-theseus/tsconfig.json",
"./packages/commitlint-config/tsconfig.json",
"./.examples/tic-tac-toe/tsconfig.json",
],
ecmaVersion: 2018,
sourceType: "module",
tsconfigRootDir: "./",
Expand Down
15 changes: 10 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
name: Build

on:
workflow_run:
workflows: ["Test"]
types:
- completed
workflow_dispatch: {}
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest

steps:
Expand All @@ -29,6 +31,9 @@ jobs:
- name: Install dependencies
run: pnpm install

- name: Run tests
run: pnpm test

- name: Run build
run: pnpm build:ci:pkg # Assuming pnpm and node_modules are correctly configured to be available

Expand Down
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.*
tsconfig.json
/src
/packages/publisher
/packages/**/*
node_modules
pnpm-workspace.yaml
*.map
Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
"lint": "git add . && pnpm lint-staged",
"lint-fix": "eslint ./ --fix --resolve-plugins-relative-to=./",
"test:debug": "node --import=tsx ./node_modules/mocha/bin/mocha.js --exit --config ./.mocharc.cjs --debug-mode",
"test": "node --import=tsx ./node_modules/mocha/bin/mocha.js --exit --config ./.mocharc.cjs",
"test:base": "node --import=tsx ./node_modules/mocha/bin/mocha.js --exit --config ./.mocharc.cjs",
"test:pkg": "for dir in packages/*/; do (cd \"$dir\" && [ -f package.json ] && pnpm test); done",
"test": "pnpm test:base && pnpm test:pkg",
"// ==== BUILD ==== //": "",
"build:base": "tsc --project ./tsconfig.json && resolve-tspaths",
"build:ci": "pnpm build:base",
Expand Down Expand Up @@ -57,7 +59,6 @@
"@semantic-release/release-notes-generator": "^13.0.0",
"@theseus/commitlint-config": "workspace:latest",
"@theseus/gpt-zip": "workspace:latest",
"@theseus/publisher": "workspace:latest",
"@types/chai": "^4.3.12",
"@types/chai-as-promised": "^7.1.8",
"@types/deep-equal": "^1.0.4",
Expand Down Expand Up @@ -88,10 +89,10 @@
"prettier-eslint": "^16.3.0",
"resolve-tspaths": "^0.8.18",
"semantic-release": "^23.1.1",
"sinon": "^17.0.1",
"sinon": "^18.0.0",
"sinon-chai": "^3.7.0",
"tsx": "^4.7.1",
"typescript": "^5.4.2"
"tsx": "^4.11.0",
"typescript": "^5.4.5"
},
"lint-staged": {
"*.ts": [
Expand Down
5 changes: 3 additions & 2 deletions packages/commitlint-config/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"name": "@theseus/commitlint-config",
"private": true,
"type": "module",
"type": "module",
"version": "1.0.0",
"description": "",
"main": "./dist/index.js",
"scripts": {
"build": "tsc"
"build": "tsc",
"test": "echo 'no tests'"
},
"keywords": [],
"author": "",
Expand Down
1 change: 0 additions & 1 deletion packages/commitlint-config/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export default {
"always",
[
"build",
"chore",
"ci",
"docs",
"feat",
Expand Down
26 changes: 13 additions & 13 deletions packages/eslint-plugin-theseus/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/* eslint-disable no-undef */
module.exports = {
rules: {
"break-on-chainable": require("./rules/break-on-chainable"),
},
configs: {
recommended: {
plugins: [
"theseus", // This should match the name of your plugin
],
rules: {
"theseus/break-on-chainable": "error",
},
},
},
rules: {
"break-on-chainable": require("./rules/break-on-chainable"),
},
configs: {
recommended: {
plugins: [
"theseus", // This should match the name of your plugin
],
rules: {
"theseus/break-on-chainable": "error",
},
},
},
};
96 changes: 48 additions & 48 deletions packages/eslint-plugin-theseus/lib/rules/break-on-chainable.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,55 +6,55 @@
//------------------------------------------------------------------------------

module.exports = {
meta: {
type: "layout",
docs: {
description: "Require a newline before specific method or property access in a chain",
recommended: false,
url: "https://eslint.org/docs/latest/rules/newline-per-chained-call",
},
fixable: "whitespace",
schema: [], // No options in this simplified version
messages: {
expected: "Expected line break before `.{{property}}`.",
},
},
meta: {
type: "layout",
docs: {
description: "Require a newline before specific method or property access in a chain",
recommended: false,
url: "https://eslint.org/docs/latest/rules/newline-per-chained-call",
},
fixable: "whitespace",
schema: [], // No options in this simplified version
messages: {
expected: "Expected line break before `.{{property}}`.",
},
},


create(context)
{
const sourceCode = context.getSourceCode();
const targetedMethods = ["and", "lastly", "result", "resultAsync"];
create(context)
{
const sourceCode = context.getSourceCode();
const targetedMethods = ["and", "lastly", "result", "resultAsync"];

return {
"Identifier"(node)
{
if (targetedMethods.includes(node.name) && node.parent.type === "MemberExpression")
{
// Only consider the direct .property access case, ensuring it's part of a member expression chain
const tokenBeforeNode = sourceCode.getTokenBefore(node, { includeComments: false });
if (tokenBeforeNode && tokenBeforeNode.type === "Punctuator" && tokenBeforeNode.value === ".")
{
const dotBeforeNode = tokenBeforeNode;
const tokenBeforeDot = sourceCode.getTokenBefore(dotBeforeNode, { includeComments: false });
if (tokenBeforeDot && tokenBeforeDot.loc.end.line === node.loc.start.line)
{
// Report if the dot connecting this property to the previous is on the same line
context.report({
node: node,
messageId: "expected",
data: {
property: node.name,
},
fix(fixer)
{
return fixer.insertTextBefore(tokenBeforeNode, "\n");
},
});
}
}
}
},
};
},
return {
"Identifier"(node)
{
if (targetedMethods.includes(node.name) && node.parent.type === "MemberExpression")
{
// Only consider the direct .property access case, ensuring it's part of a member expression chain
const tokenBeforeNode = sourceCode.getTokenBefore(node, { includeComments: false });
if (tokenBeforeNode && tokenBeforeNode.type === "Punctuator" && tokenBeforeNode.value === ".")
{
const dotBeforeNode = tokenBeforeNode;
const tokenBeforeDot = sourceCode.getTokenBefore(dotBeforeNode, { includeComments: false });
if (tokenBeforeDot && tokenBeforeDot.loc.end.line === node.loc.start.line)
{
// Report if the dot connecting this property to the previous is on the same line
context.report({
node: node,
messageId: "expected",
data: {
property: node.name,
},
fix(fixer)
{
return fixer.insertTextBefore(tokenBeforeNode, "\n");
},
});
}
}
}
},
};
},
};
94 changes: 47 additions & 47 deletions packages/eslint-plugin-theseus/lib/tests/break-on-chainable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,54 +5,54 @@ const rule = require("../rules/break-on-chainable");

// Use the appropriate parser if dealing with specific ECMAScript versions or TypeScript
const ruleTester = new RuleTester({
parserOptions: { ecmaVersion: 2020, sourceType: "module" },
parserOptions: { ecmaVersion: 2020, sourceType: "module" },
});

ruleTester.run("break-on-chainable", rule, {
valid: [
{
code: "obj.via.thing()\n.and.anotherThing()",
},
{
code: "obj.via.thing()\n.lastly.thing()",
},
{
code: "obj.via.thing()\n.result",
},
{
code: "obj.via.thing()\n.resultAsync",
},
],
invalid: [
{
code: "obj.via.thing().and.anotherThing().lastly.thing();",
errors: [
{ message: "Expected line break before `.and`." },
{ message: "Expected line break before `.lastly`." },
],
output: "obj.via.thing()\n.and.anotherThing()\n.lastly.thing();",
},
{
code: "obj.via.thing().result;",
errors: [
{ message: "Expected line break before `.result`." },
],
output: "obj.via.thing()\n.result;",
},
{
code: "obj.via.thing().resultAsync;",
errors: [
{ message: "Expected line break before `.resultAsync`." },
],
output: "obj.via.thing()\n.resultAsync;",
},
{
code: "GameMeta.iterateTurnCount().and.updateLastPlayer(mark).and.updateLastPlayedCoords(coords);",
errors: [
{ message: "Expected line break before `.and`." },
{ message: "Expected line break before `.and`." },
],
output: "GameMeta.iterateTurnCount()\n.and.updateLastPlayer(mark)\n.and.updateLastPlayedCoords(coords);",
},
],
valid: [
{
code: "obj.via.thing()\n.and.anotherThing()",
},
{
code: "obj.via.thing()\n.lastly.thing()",
},
{
code: "obj.via.thing()\n.result",
},
{
code: "obj.via.thing()\n.resultAsync",
},
],
invalid: [
{
code: "obj.via.thing().and.anotherThing().lastly.thing();",
errors: [
{ message: "Expected line break before `.and`." },
{ message: "Expected line break before `.lastly`." },
],
output: "obj.via.thing()\n.and.anotherThing()\n.lastly.thing();",
},
{
code: "obj.via.thing().result;",
errors: [
{ message: "Expected line break before `.result`." },
],
output: "obj.via.thing()\n.result;",
},
{
code: "obj.via.thing().resultAsync;",
errors: [
{ message: "Expected line break before `.resultAsync`." },
],
output: "obj.via.thing()\n.resultAsync;",
},
{
code: "GameMeta.iterateTurnCount().and.updateLastPlayer(mark).and.updateLastPlayedCoords(coords);",
errors: [
{ message: "Expected line break before `.and`." },
{ message: "Expected line break before `.and`." },
],
output: "GameMeta.iterateTurnCount()\n.and.updateLastPlayer(mark)\n.and.updateLastPlayedCoords(coords);",
},
],
});
4 changes: 2 additions & 2 deletions packages/eslint-plugin-theseus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
"mocha": "^10.3.0"
},
"keywords": [],
"author": "",
"license": "ISC"
"author": "Jake Lauer",
"license": "MIT"
}
Loading

0 comments on commit 915a191

Please sign in to comment.