Skip to content

Commit

Permalink
Merge branch 'main' into shew-fa421
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyshew authored Nov 14, 2024
2 parents c6670b8 + 5d1ecc3 commit 2f9a59c
Show file tree
Hide file tree
Showing 21 changed files with 343 additions and 53 deletions.
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/0-turborepo-bug-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: Turborepo bug report
description: Create a bug report
labels: ["kind: bug", "needs: triage"]
title: "🐛 Bug: "

body:
- type: markdown
attributes:
Expand Down
28 changes: 25 additions & 3 deletions crates/turborepo-env/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{
ops::{Deref, DerefMut},
};

use regex::Regex;
use regex::RegexBuilder;
use serde::Serialize;
use sha2::{Digest, Sha256};
use thiserror::Error;
Expand Down Expand Up @@ -180,8 +180,13 @@ impl EnvironmentVariableMap {
let include_regex_string = format!("^({})$", include_patterns.join("|"));
let exclude_regex_string = format!("^({})$", exclude_patterns.join("|"));

let include_regex = Regex::new(&include_regex_string)?;
let exclude_regex = Regex::new(&exclude_regex_string)?;
let case_insensitive = cfg!(windows);
let include_regex = RegexBuilder::new(&include_regex_string)
.case_insensitive(case_insensitive)
.build()?;
let exclude_regex = RegexBuilder::new(&exclude_regex_string)
.case_insensitive(case_insensitive)
.build()?;
for (env_var, env_value) in &self.0 {
if !include_patterns.is_empty() && include_regex.is_match(env_var) {
output.inclusions.insert(env_var.clone(), env_value.clone());
Expand Down Expand Up @@ -304,6 +309,8 @@ pub fn get_global_hashable_env_vars(
mod tests {
use test_case::test_case;

use super::*;

#[test_case("LITERAL_\\*", "LITERAL_\\*" ; "literal star")]
#[test_case("\\*LEADING", "\\*LEADING" ; "leading literal star")]
#[test_case("\\!LEADING", "\\\\!LEADING" ; "leading literal bang")]
Expand All @@ -313,4 +320,19 @@ mod tests {
let actual = super::wildcard_to_regex_pattern(pattern);
assert_eq!(actual, expected);
}

#[test]
fn test_case_sensitivity() {
let start = EnvironmentVariableMap(
vec![("Turbo".to_string(), "true".to_string())]
.into_iter()
.collect(),
);
let actual = start.from_wildcards(&["TURBO"]).unwrap();
if cfg!(windows) {
assert_eq!(actual.get("Turbo").map(|s| s.as_str()), Some("true"));
} else {
assert_eq!(actual.get("Turbo"), None);
}
}
}
6 changes: 0 additions & 6 deletions crates/turborepo-lib/src/task_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,12 +506,6 @@ impl<'a> TaskHasher<'a> {
"PROGRAMDATA",
"SYSTEMROOT",
"SYSTEMDRIVE",
// Powershell casing of env variables
"Path",
"ProgramData",
"SystemRoot",
"AppData",
"SystemDrive",
])?;
let tracker_env = self
.task_hash_tracker
Expand Down
2 changes: 1 addition & 1 deletion packages/create-turbo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-turbo",
"version": "2.2.4-canary.10",
"version": "2.3.0",
"description": "Create a new Turborepo",
"homepage": "https://turbo.build/repo",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config-turbo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-config-turbo",
"version": "2.2.4-canary.10",
"version": "2.3.0",
"description": "ESLint config for Turborepo",
"repository": {
"type": "git",
Expand Down
55 changes: 52 additions & 3 deletions packages/eslint-plugin-turbo/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# `eslint-plugin-turbo`

Ease configuration for Turborepo
Easy ESLint configuration for Turborepo

## Installation

Expand All @@ -16,7 +16,7 @@ npm install eslint --save-dev
npm install eslint-plugin-turbo --save-dev
```

## Usage
## Usage (Legacy `eslintrc*`)

Add `turbo` to the plugins section of your `.eslintrc` configuration file. You can omit the `eslint-plugin-` prefix:

Expand All @@ -36,7 +36,7 @@ Then configure the rules you want to use under the rules section.
}
```

### Example
## Example (Legacy `eslintrc*`)

```json
{
Expand All @@ -51,3 +51,52 @@ Then configure the rules you want to use under the rules section.
}
}
```

## Usage (Flat Config `eslint.config.js`)

In ESLint v8, both the legacy system and the new flat config system are supported. In ESLint v9, only the new system will be supported. See the [official ESLint docs](https://eslint.org/docs/latest/use/configure/configuration-files).

```js
import turbo from "eslint-plugin-turbo";

export default [turbo.configs["flat/recommended"]];
```

Otherwise, you may configure the rules you want to use under the rules section.

```js
import turbo from "eslint-plugin-turbo";

export default [
{
plugins: {
turbo,
},
rules: {
"turbo/no-undeclared-env-vars": "error",
},
},
];
```

## Example (Flat Config `eslint.config.js`)

```js
import turbo from "eslint-plugin-turbo";

export default [
{
plugins: {
turbo,
},
rules: {
"turbo/no-undeclared-env-vars": [
"error",
{
allowList: ["^ENV_[A-Z]+$"],
},
],
},
},
];
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const turbo = require("eslint-plugin-turbo");

module.exports = [turbo.configs["flat/recommended"]];
9 changes: 9 additions & 0 deletions packages/eslint-plugin-turbo/__tests__/cwd.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import { parse, stringify } from "json5";
import { setupTestFixtures } from "@turbo/test-utils";
import { describe, it, expect } from "@jest/globals";

const env: NodeJS.ProcessEnv = {
...process.env,
ESLINT_USE_FLAT_CONFIG: "false",
};

describe("eslint settings check", () => {
const { useFixture } = setupTestFixtures({
directory: path.join(__dirname, "../"),
Expand All @@ -17,6 +22,7 @@ describe("eslint settings check", () => {
const configString = execSync(`npm exec eslint -- --print-config peer.js`, {
cwd,
encoding: "utf8",
env,
});
const configJson: Record<string, unknown> = parse(configString);

Expand Down Expand Up @@ -76,6 +82,7 @@ describe("eslint settings check", () => {
{
cwd,
encoding: "utf8",
env,
}
);
const configJson: Record<string, unknown> = parse(configString);
Expand Down Expand Up @@ -144,6 +151,7 @@ describe("eslint cache is busted", () => {
execSync(`npm exec eslint -- --format=json child.js`, {
cwd,
encoding: "utf8",
env,
});
} catch (error: unknown) {
const outputJson: Record<string, unknown> = parse(
Expand Down Expand Up @@ -172,6 +180,7 @@ describe("eslint cache is busted", () => {
const output = execSync(`npm exec eslint -- --format=json child.js`, {
cwd,
encoding: "utf8",
env,
});
const outputJson: Record<string, unknown> = parse(output);
expect(outputJson).toMatchObject([{ errorCount: 0 }]);
Expand Down
Loading

0 comments on commit 2f9a59c

Please sign in to comment.