Skip to content

Commit

Permalink
feat(eslint): support turbo.json workspace configs (#3846)
Browse files Browse the repository at this point in the history
Support turbo.json workspace configs. 

Still to do:
- [x] Support workspace specific linting

There exists one edge case here, if a user forgets to add an "extend" to workspace config, we _can_ treat it as root. I punted on this one for now since it's not this packages domain to solve that (at the moment)
  • Loading branch information
tknickman committed Feb 17, 2023
1 parent a9ab07f commit 30060f3
Show file tree
Hide file tree
Showing 44 changed files with 805 additions and 197 deletions.
10 changes: 5 additions & 5 deletions packages/eslint-plugin-turbo/__tests__/cwd.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe("eslint settings check", () => {
cwd,
encoding: "utf8",
});
const configJson = JSON.parse(configString);
const configJson = JSON5.parse(configString);

expect(configJson.settings).toEqual({
turbo: { envVars: ["CI", "UNORDERED"] },
Expand All @@ -38,7 +38,7 @@ describe("eslint settings check", () => {
cwd,
encoding: "utf8",
});
const configJson = JSON.parse(configString);
const configJson = JSON5.parse(configString);

expect(configJson.settings).toEqual({
turbo: { envVars: ["CI", "UNORDERED"] },
Expand Down Expand Up @@ -82,13 +82,13 @@ describe("eslint cache is busted", () => {
try {
execSync(`eslint --format=json child.js`, { cwd, encoding: "utf8" });
} catch (error: any) {
const outputJson = JSON.parse(error.stdout);
const outputJson = JSON5.parse(error.stdout);
expect(outputJson).toMatchObject([
{
messages: [
{
message:
"$NONEXISTENT is not listed as a dependency in turbo.json",
"$NONEXISTENT is not listed as a dependency in any turbo.json",
},
],
},
Expand All @@ -105,7 +105,7 @@ describe("eslint cache is busted", () => {
cwd,
encoding: "utf8",
});
const outputJson = JSON.parse(output);
const outputJson = JSON5.parse(output);
expect(outputJson).toMatchObject([{ errorCount: 0 }]);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"globalEnv":[
"NEW_STYLE_GLOBAL_ENV_KEY",
"$NEW_STYLE_GLOBAL_ENV_KEY"
],
"globalDependencies":[
"$GLOBAL_ENV_KEY"
],
"pipeline":{
"test":{
"outputs":[
"coverage/**"
],
"dependsOn":[
"^build"
]
},
"lint":{
"outputs":[]
},
"dev":{
"cache":false
},
"build":{
"outputs":[
"dist/**/*",
".next/**/*"
],
"env":[
"NEW_STYLE_ENV_KEY"
],
"dependsOn":[
"^build",
"$TASK_ENV_KEY",
"$ANOTHER_ENV_KEY"
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default function docs() {
if (process.env.ENV_1 === undefined) {
return 'does not exist';
}
return 'exists'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "docs",
"version": "1.0.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default function web() {
if (!process.env.ENV_2) {
return 'bar';
}
return 'foo'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "web",
"version": "1.0.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://turbo.build/schema.json",
"extends": ["//"],
"pipeline": {
"build": {
"env": ["ENV_2"]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"private": true,
"workspaces": [
"apps/*",
"packages/*"
],
"scripts": {
"build": "turbo run build"
},
"devDependencies": {
"turbo": "latest"
},
"packageManager": "yarn@1.22.19"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default function foo() {
if (!process.env.IS_SERVER) {
return 'bar';
}
return 'foo'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "ui",
"version": "1.0.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://turbo.build/schema.json",
"extends": ["//"],
"pipeline": {
"build": {
"env": ["IS_SERVER"]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://turbo.build/schema.json",
"globalEnv": ["CI"],
"pipeline": {
"build": {
"env": ["ENV_1"]
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 0 additions & 34 deletions packages/eslint-plugin-turbo/__tests__/lib/findTurboConfig.test.ts

This file was deleted.

Loading

0 comments on commit 30060f3

Please sign in to comment.