Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add common Sass TypeScript configuration to the analysis package #2333

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
version: 2
updates:
- package-ecosystem: "pub"
directory: "/"
directories:
- "/"
- "/analysis"
schedule:
interval: "weekly"
- package-ecosystem: "github-actions"
Expand All @@ -13,6 +15,7 @@ updates:
- package-ecosystem: "npm"
directories:
- "/"
- "/analysis"
- "/package"
- "/pkg/sass-parser"
ignore:
Expand Down
23 changes: 23 additions & 0 deletions analysis/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"extends": "./node_modules/gts/",
"plugins": ["import"],
"rules": {
"@typescript-eslint/explicit-function-return-type": [
"error",
{"allowExpressions": true}
],
"func-style": ["error", "declaration"],
"prefer-const": ["error", {"destructuring": "all"}],
// It would be nice to sort import declaration order as well, but that's not
// autofixable and it's not worth the effort of handling manually.
"sort-imports": ["error", {"ignoreDeclarationSort": true}],
},
"overrides": [
{
"files": ["**/*.ts"],
"rules": {
"import/no-commonjs": "error"
}
}
]
}
3 changes: 3 additions & 0 deletions analysis/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
...require('gts/.prettierrc.json'),
};
58 changes: 54 additions & 4 deletions analysis/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,65 @@
This package provides a shared set of analysis options for use by Sass team
packages. To use it, add it as a Git dependency to your `pubspec.yaml`:
This package provides a shared static analysis configuration for use by Sass
team Dart and TypeScript packages.

## Use from Dart

Add this as a Git dependency to your `pubspec.yaml`:

```yaml
dev_dependencies:
sass_analysis:
git: {url:
https://github.com/sass/dart-sass.git, path: analysis}
git: {url: https://github.com/sass/dart-sass.git, path: analysis}
```

and include it in your `analysis_options.yaml`:

```yaml
include: package:sass_analysis/analysis_options.yaml
```

## Use from TypeScript

Add this and [gts] as Git dependencies to your `package.json`, then initialize
gts:

[gts]: https://github.com/google/gts

```sh
$ npm i --save-dev gts 'https://gitpkg.vercel.app/sass/dart-sass/analysis?main'
$ npx gts init
```

Then edit the configuration files to use Sass-specific customizations instead of
the gts defaults:

* `eslintrc.json`:

```json
{
"extends": "./node_modules/sass-analysis/"
}
```

* `.prettierrc.js`:

```json
module.exports = {
...require(sass-analysis/.prettierrc.js')
}
```

* `tsconfig.json`:

```json
{
"extends": "./node_modules/sass-analysis/tsconfig.json",
"compilerOptions": {
"rootDir": ".",
"outDir": "build"
},
"include": [
"src/**/*.ts",
"test/**/*.ts"
]
}
```
6 changes: 6 additions & 0 deletions analysis/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const fs = require('node:fs');
const jsonc = require('jsonc-parser');

module.exports = jsonc.parse(
fs.readFileSync(require.resolve('./.eslintrc'), 'utf8')
);
10 changes: 10 additions & 0 deletions analysis/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "sass-analysis",
"version": "0.0.0",
"description": "Shared static analysis options for Sass team packages.",
"dependencies": {
"eslint-plugin-import": "^2.30.0",
"gts": "^5.0.0",
"jsonc-parser": "^3.3.1"
}
}
2 changes: 1 addition & 1 deletion analysis/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: sass_analysis
version: 0.0.0
description: Shared analysis options for Sass team packages.
homepage: https://github.com/sass/dart-sass/tree/master/analysis
homepage: https://github.com/sass/dart-sass/tree/main/analysis

publish_to: none

Expand Down
3 changes: 3 additions & 0 deletions analysis/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "./node_modules/gts/tsconfig-google.json"
}
13 changes: 1 addition & 12 deletions pkg/sass-parser/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
{
"extends": "./node_modules/gts/",
"rules": {
"@typescript-eslint/explicit-function-return-type": [
"error",
{"allowExpressions": true}
],
"func-style": ["error", "declaration"],
"prefer-const": ["error", {"destructuring": "all"}],
// It would be nice to sort import declaration order as well, but that's not
// autofixable and it's not worth the effort of handling manually.
"sort-imports": ["error", {"ignoreDeclarationSort": true}],
}
"extends": "./node_modules/sass-analysis/"
}
2 changes: 1 addition & 1 deletion pkg/sass-parser/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
...require('gts/.prettierrc.json'),
...require('sass-analysis/.prettierrc.js'),
};
7 changes: 3 additions & 4 deletions pkg/sass-parser/lib/src/stringifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,12 @@
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

import * as postcss from 'postcss';
import PostCssStringifier from 'postcss/lib/stringifier';

import {AnyStatement} from './statement';
import {GenericAtRule} from './statement/generic-at-rule';
import {Rule} from './statement/rule';

const PostCssStringifier = require('postcss/lib/stringifier');

/**
* A visitor that stringifies Sass statements.
*
Expand Down Expand Up @@ -67,7 +66,7 @@ export class Stringifier extends PostCssStringifier {
)(statement, semicolon);
}

private atrule(node: GenericAtRule, semicolon: boolean): void {
atrule(node: GenericAtRule, semicolon: boolean): void {
const start =
`@${node.nameInterpolation}` +
(node.raws.afterName ?? (node.paramsInterpolation ? ' ' : '')) +
Expand All @@ -82,7 +81,7 @@ export class Stringifier extends PostCssStringifier {
}
}

private rule(node: Rule): void {
rule(node: Rule): void {
this.block(node, node.selectorInterpolation.toString());
}
}
2 changes: 2 additions & 0 deletions pkg/sass-parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@
"devDependencies": {
"@types/jest": "^29.5.12",
"copyfiles": "^2.4.1",
"eslint-plugin-import": "^2.30.0",
"expect": "^29.7.0",
"gts": "^5.0.0",
"jest": "^29.4.1",
"jest-extended": "^4.0.2",
"npm-run-all": "^4.1.5",
"rimraf": "^6.0.1",
"sass-analysis": "file:../../analysis",
"ts-jest": "^29.0.5",
"ts-node": "^10.2.1",
"typedoc": "^0.26.5",
Expand Down
2 changes: 1 addition & 1 deletion pkg/sass-parser/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "./node_modules/gts/tsconfig-google.json",
"extends": "./node_modules/sass-analysis/tsconfig.json",
"compilerOptions": {
"lib": ["es2022"],
"allowJs": true,
Expand Down
Loading