Skip to content

Commit fe75225

Browse files
committed
Add common Sass TypeScript configuration to the analysis package
1 parent a42925c commit fe75225

File tree

12 files changed

+106
-24
lines changed

12 files changed

+106
-24
lines changed

.github/dependabot.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
version: 2
22
updates:
33
- package-ecosystem: "pub"
4-
directory: "/"
4+
directories:
5+
- "/"
6+
- "/analysis"
57
schedule:
68
interval: "weekly"
79
- package-ecosystem: "github-actions"
@@ -13,6 +15,7 @@ updates:
1315
- package-ecosystem: "npm"
1416
directories:
1517
- "/"
18+
- "/analysis"
1619
- "/package"
1720
- "/pkg/sass-parser"
1821
ignore:

analysis/.eslintrc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"extends": "./node_modules/gts/",
3+
"plugins": ["import"],
4+
"rules": {
5+
"@typescript-eslint/explicit-function-return-type": [
6+
"error",
7+
{"allowExpressions": true}
8+
],
9+
"func-style": ["error", "declaration"],
10+
"prefer-const": ["error", {"destructuring": "all"}],
11+
// It would be nice to sort import declaration order as well, but that's not
12+
// autofixable and it's not worth the effort of handling manually.
13+
"sort-imports": ["error", {"ignoreDeclarationSort": true}],
14+
},
15+
"overrides": [
16+
{
17+
"files": ["**/*.ts"],
18+
"rules": {
19+
"import/no-commonjs": "error"
20+
}
21+
}
22+
]
23+
}

analysis/.prettierrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
...require('gts/.prettierrc.json'),
3+
};

analysis/README.md

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,65 @@
1-
This package provides a shared set of analysis options for use by Sass team
2-
packages. To use it, add it as a Git dependency to your `pubspec.yaml`:
1+
This package provides a shared static analysis configuration for use by Sass
2+
team Dart and TypeScript packages.
3+
4+
## Use from Dart
5+
6+
Add this as a Git dependency to your `pubspec.yaml`:
37

48
```yaml
59
dev_dependencies:
610
sass_analysis:
7-
git: {url:
8-
https://github.com/sass/dart-sass.git, path: analysis}
11+
git: {url: https://github.com/sass/dart-sass.git, path: analysis}
912
```
1013
1114
and include it in your `analysis_options.yaml`:
1215

1316
```yaml
1417
include: package:sass_analysis/analysis_options.yaml
1518
```
19+
20+
## Use from TypeScript
21+
22+
Add this and [gts] as Git dependencies to your `package.json`, then initialize
23+
gts:
24+
25+
[gts]: https://github.com/google/gts
26+
27+
```sh
28+
$ npm i --save-dev gts 'https://gitpkg.vercel.app/sass/dart-sass/analysis?main'
29+
$ npx gts init
30+
```
31+
32+
Then edit the configuration files to use Sass-specific customizations instead of
33+
the gts defaults:
34+
35+
* `eslintrc.json`:
36+
37+
```json
38+
{
39+
"extends": "./node_modules/sass-analysis/"
40+
}
41+
```
42+
43+
* `.prettierrc.js`:
44+
45+
```json
46+
module.exports = {
47+
...require(sass-analysis/.prettierrc.js')
48+
}
49+
```
50+
51+
* `tsconfig.json`:
52+
53+
```json
54+
{
55+
"extends": "./node_modules/sass-analysis/tsconfig.json",
56+
"compilerOptions": {
57+
"rootDir": ".",
58+
"outDir": "build"
59+
},
60+
"include": [
61+
"src/**/*.ts",
62+
"test/**/*.ts"
63+
]
64+
}
65+
```

analysis/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "sass-analysis",
3+
"version": "0.0.0",
4+
"description": "Shared static analysis options for Sass team packages.",
5+
"dependencies": {
6+
"eslint-plugin-import": "^2.30.0",
7+
"gts": "^5.0.0",
8+
"jsonc-parser": "^3.3.1"
9+
}
10+
}

analysis/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: sass_analysis
22
version: 0.0.0
33
description: Shared analysis options for Sass team packages.
4-
homepage: https://github.com/sass/dart-sass/tree/master/analysis
4+
homepage: https://github.com/sass/dart-sass/tree/main/analysis
55

66
publish_to: none
77

analysis/tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "./node_modules/gts/tsconfig-google.json"
3+
}

pkg/sass-parser/.eslintrc

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
11
{
2-
"extends": "./node_modules/gts/",
3-
"rules": {
4-
"@typescript-eslint/explicit-function-return-type": [
5-
"error",
6-
{"allowExpressions": true}
7-
],
8-
"func-style": ["error", "declaration"],
9-
"prefer-const": ["error", {"destructuring": "all"}],
10-
// It would be nice to sort import declaration order as well, but that's not
11-
// autofixable and it's not worth the effort of handling manually.
12-
"sort-imports": ["error", {"ignoreDeclarationSort": true}],
13-
}
2+
"extends": "./node_modules/sass-analysis/"
143
}

pkg/sass-parser/.prettierrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module.exports = {
2-
...require('gts/.prettierrc.json'),
2+
...require('sass-analysis/.prettierrc.js'),
33
};

pkg/sass-parser/lib/src/stringifier.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,12 @@
2727
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2828

2929
import * as postcss from 'postcss';
30+
import PostCssStringifier from 'postcss/lib/stringifier';
3031

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

35-
const PostCssStringifier = require('postcss/lib/stringifier');
36-
3736
/**
3837
* A visitor that stringifies Sass statements.
3938
*
@@ -67,7 +66,7 @@ export class Stringifier extends PostCssStringifier {
6766
)(statement, semicolon);
6867
}
6968

70-
private atrule(node: GenericAtRule, semicolon: boolean): void {
69+
atrule(node: GenericAtRule, semicolon: boolean): void {
7170
const start =
7271
`@${node.nameInterpolation}` +
7372
(node.raws.afterName ?? (node.paramsInterpolation ? ' ' : '')) +
@@ -82,7 +81,7 @@ export class Stringifier extends PostCssStringifier {
8281
}
8382
}
8483

85-
private rule(node: Rule): void {
84+
rule(node: Rule): void {
8685
this.block(node, node.selectorInterpolation.toString());
8786
}
8887
}

0 commit comments

Comments
 (0)