Skip to content

Commit 6f20a43

Browse files
nzakasfasttime
andauthored
feat: Rename to @eslint/css-tree (#1)
* feat: Rename to @eslint/css-tree * Update references * Update package.json Co-authored-by: Francesco Trotta <github@fasttime.org> * Revert CHANGELOG changes * Update module names in script * Update package-lock.json --------- Co-authored-by: Francesco Trotta <github@fasttime.org>
1 parent b3fe3e0 commit 6f20a43

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+146
-140
lines changed

LICENSE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Copyright (C) 2016-2024 by Roman Dvornov
2+
Copyright OpenJS Foundation and other contributors, <www.openjsf.org>
23

34
Permission is hereby granted, free of charge, to any person obtaining a copy
45
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
<img align="right" width="111" height="111" alt="CSSTree logo" src="assets/csstree-logo-rounded.svg" />
22

3-
# CSSTree
4-
5-
[![NPM version](https://img.shields.io/npm/v/css-tree.svg)](https://www.npmjs.com/package/css-tree)
6-
[![Build Status](https://github.com/csstree/csstree/actions/workflows/build.yml/badge.svg)](https://github.com/csstree/csstree/actions/workflows/build.yml)
7-
[![Coverage Status](https://coveralls.io/repos/github/csstree/csstree/badge.svg?branch=master)](https://coveralls.io/github/csstree/csstree?branch=master)
8-
[![NPM Downloads](https://img.shields.io/npm/dm/css-tree.svg)](https://www.npmjs.com/package/css-tree)
9-
[![Twitter](https://img.shields.io/badge/Twitter-@csstree-blue.svg)](https://twitter.com/csstree)
3+
# CSSTree (ESLint Fork)
104

115
CSSTree is a tool set for CSS: [fast](https://github.com/postcss/benchmark) detailed parser (CSS → AST), walker (AST traversal), generator (AST → CSS) and lexer (validation and matching) based on specs and browser implementations. The main goal is to be efficient and W3C spec compliant, with focus on CSS analyzing and source-to-source transforming tasks.
126

@@ -90,13 +84,13 @@ CSSTree is a tool set for CSS: [fast](https://github.com/postcss/benchmark) deta
9084
Install with npm:
9185

9286
```
93-
npm install css-tree
87+
npm install @eslint/css-tree
9488
```
9589

9690
Basic usage:
9791

9892
```js
99-
import * as csstree from 'css-tree';
93+
import * as csstree from '@eslint/css-tree';
10094

10195
// parse CSS to AST
10296
const ast = csstree.parse('.example { world: "!" }');
@@ -136,17 +130,17 @@ console.log(matchResult.getTrace(ast.children.first));
136130

137131
### Exports
138132

139-
Is it possible to import just a needed part of library like a parser or a walker. That's might useful for loading time or bundle size optimisations.
133+
Is it possible to import just a needed part of library like a parser or a walker. That's might useful for loading time or bundle size optimisations.
140134

141135
```js
142-
import * as tokenizer from 'css-tree/tokenizer';
143-
import * as parser from 'css-tree/parser';
144-
import * as walker from 'css-tree/walker';
145-
import * as lexer from 'css-tree/lexer';
146-
import * as definitionSyntax from 'css-tree/definition-syntax';
147-
import * as data from 'css-tree/definition-syntax-data';
148-
import * as dataPatch from 'css-tree/definition-syntax-data-patch';
149-
import * as utils from 'css-tree/utils';
136+
import * as tokenizer from '@eslint/css-tree/tokenizer';
137+
import * as parser from '@eslint/css-tree/parser';
138+
import * as walker from '@eslint/css-tree/walker';
139+
import * as lexer from '@eslint/css-tree/lexer';
140+
import * as definitionSyntax from '@eslint/css-tree/definition-syntax';
141+
import * as data from '@eslint/css-tree/definition-syntax-data';
142+
import * as dataPatch from '@eslint/css-tree/definition-syntax-data-patch';
143+
import * as utils from '@eslint/css-tree/utils';
150144
```
151145

152146
### Using in a browser
@@ -155,7 +149,7 @@ Bundles are available for use in a browser:
155149

156150
- `dist/csstree.js` – minified IIFE with `csstree` as global
157151
```html
158-
<script src="node_modules/css-tree/dist/csstree.js"></script>
152+
<script src="node_modules/@eslint/css-tree/dist/csstree.js"></script>
159153
<script>
160154
csstree.parse('.example { color: green }');
161155
</script>
@@ -164,7 +158,7 @@ Bundles are available for use in a browser:
164158
- `dist/csstree.esm.js` – minified ES module
165159
```html
166160
<script type="module">
167-
import { parse } from 'node_modules/css-tree/dist/csstree.esm.js'
161+
import { parse } from 'node_modules/@eslint/css-tree/dist/csstree.esm.js'
168162
parse('.example { color: green }');
169163
</script>
170164
```
@@ -174,19 +168,27 @@ One of CDN services like `unpkg` or `jsDelivr` can be used. By default (for shor
174168
```html
175169
<!-- ESM -->
176170
<script type="module">
177-
import * as csstree from 'https://cdn.jsdelivr.net/npm/css-tree';
178-
import * as csstree from 'https://unpkg.com/css-tree';
171+
import * as csstree from 'https://cdn.jsdelivr.net/npm/@eslint/css-tree';
172+
import * as csstree from 'https://unpkg.com/@eslint/css-tree';
179173
</script>
180174

181175
<!-- IIFE with an export to global -->
182-
<script src="https://cdn.jsdelivr.net/npm/css-tree/dist/csstree.js"></script>
183-
<script src="https://unpkg.com/css-tree/dist/csstree.js"></script>
176+
<script src="https://cdn.jsdelivr.net/npm/@eslint/css-tree/dist/csstree.js"></script>
177+
<script src="https://unpkg.com/@eslint/css-tree/dist/csstree.js"></script>
184178
```
185179

186180
## Top level API
187181

188-
![API map](https://cdn.rawgit.com/csstree/csstree/aaf327e/docs/api-map.svg)
182+
![API map](https://cdn.rawgit.com/eslint/csstree/aaf327e/docs/api-map.svg)
189183

190184
## License
191185

192186
MIT
187+
188+
189+
## Branch Setup and Development
190+
191+
* `main` - the default branch for new development in the fork repo
192+
* `upstream` - kept in sync with `csstree/csstree`
193+
194+
When merging in changes from `csstree/csstree`, sync `upstream` in the GitHub UI (if possible). Then send a pull request to `main` to work through any merge conflicts.

docs/definition-syntax.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ This article describes API to work with [Value Definition Syntax](https://www.w3
2828

2929
Arguments:
3030

31-
- **source**: `string`
31+
- **source**: `string`
3232
A definition to parse
3333

3434
```js
35-
import { definitionSyntax } from 'css-tree';
35+
import { definitionSyntax } from '@eslint/css-tree';
3636

3737
definitionSyntax.parse('foo | bar');
3838
// { Group
39-
// terms:
39+
// terms:
4040
// [ { Keyword name: 'foo' },
4141
// { Keyword name: 'bar' } ],
4242
// combinator: '|',
@@ -48,15 +48,15 @@ definitionSyntax.parse('foo | bar');
4848

4949
Arguments:
5050

51-
- **node**: `Object`
51+
- **node**: `Object`
5252
AST node
53-
- **options**: `{ enter?: function, leave?: function }` or `function`
53+
- **options**: `{ enter?: function, leave?: function }` or `function`
5454
An object to specify enter and/or leave handlers. When value is a function, it treated as `{ enter: function }`. One of handlers is required.
55-
- **context** (optional): `any`
55+
- **context** (optional): `any`
5656
Defines a value as `this` in enter and leave handlers.
5757

5858
```js
59-
import { definitionSyntax } from 'css-tree';
59+
import { definitionSyntax } from '@eslint/css-tree';
6060

6161
const ast = definitionSyntax.parse('foo | bar');
6262

@@ -85,19 +85,19 @@ definitionSyntax.walk(ast, node =>
8585

8686
## generate(node, options)
8787

88-
- **node**: `Object`
88+
- **node**: `Object`
8989
AST node to generate a string from
90-
- **options** (optional): `Object`
90+
- **options** (optional): `Object`
9191
An object to specify output behaviour (all options are optional):
92-
- **forceBraces**: `Boolean` (default: `false`)
92+
- **forceBraces**: `Boolean` (default: `false`)
9393
Enforce printing brackets for any groups (even implicit). Useful for debugging and priority revelation.
94-
- **compact**: `Boolean` (default: `false`)
94+
- **compact**: `Boolean` (default: `false`)
9595
Avoid formatting (primary whitespaces around brackets and so on) when possible.
96-
- **decorate**: `function(nodeGenerateResult, node)`
96+
- **decorate**: `function(nodeGenerateResult, node)`
9797
A function to post-process result of node translation to a string. Handy to make some kind of result wrapping.
9898

9999
```js
100-
import { definitionSyntax } from 'css-tree';
100+
import { definitionSyntax } from '@eslint/css-tree';
101101

102102
const ast = definitionSyntax.parse('foo && bar || [ baz | qux ]');
103103

docs/generate.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ Options (optional):
2626

2727
### sourceMap
2828

29-
Type: `boolean`
29+
Type: `boolean`
3030
Default: `false`
3131

3232
Generates a source map (nodes should contain positions in `loc` property). Note, that an object instead of string is returned in that case.
3333

3434
```js
35-
import { parse, generate } from 'css-tree';
35+
import { parse, generate } from '@eslint/css-tree';
3636

3737
const ast = parse('.test { color: red }', {
3838
filename: 'my.css',
@@ -45,14 +45,14 @@ const result = generate(ast, { sourceMap: true });
4545

4646
### decorator
4747

48-
Type: `function`
48+
Type: `function`
4949
Default: none
5050

5151
A function that returns handlers used by a generator. TBD
5252

5353
### mode
5454

55-
Type: `"spec"` or `"safe"`
55+
Type: `"spec"` or `"safe"`
5656
Default: `"safe"`
5757

5858
CSS Syntax Module defines [rules for CSS serialization](https://www.w3.org/TR/css-syntax-3/#serialization) that it must "round-trip" with parsing. The generator follows these rules and determines itself when to output the space to avoid unintended CSS tokens combining. However, some older browsers fail to parse the resulting CSS because they didn't follow the spec in some cases. For this reason, the generator supports two modes:
@@ -61,7 +61,7 @@ CSS Syntax Module defines [rules for CSS serialization](https://www.w3.org/TR/cs
6161
- `spec` which completely follows the spec.
6262

6363
```js
64-
import { parse, generate } from 'css-tree';
64+
import { parse, generate } from '@eslint/css-tree';
6565

6666
const ast = parse('a { border: calc(1px) solid #ff0000 }');
6767

docs/parsing.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
Parses CSS into AST.
88

99
```js
10-
import { parse } from 'css-tree';
10+
import { parse } from '@eslint/css-tree';
1111

1212
// simple parsing with no options
1313
const ast = parse('.example { color: red }');
@@ -42,7 +42,7 @@ Options (optional):
4242

4343
### context
4444

45-
Type: `string`
45+
Type: `string`
4646
Default: `'stylesheet'`
4747

4848
Defines what part of CSS is parsing.
@@ -64,21 +64,21 @@ Contexts:
6464

6565
### atrule
6666

67-
Type: `string` or `null`
67+
Type: `string` or `null`
6868
Default: `null`
6969

7070
Using for `atrulePrelude` context to apply atrule specific parse rules.
7171

7272
### positions
7373

74-
Type: `boolean`
74+
Type: `boolean`
7575
Default: `false`
7676

7777
Specify to store locations of node content in original source. Location is storing as `loc` field of nodes. `loc` property is always `null` when this option is `false`. See structure of [`loc`](ast.md#loc) in AST format description.
7878

7979
### onParseError
8080

81-
Type: `function(error, fallbackNode)` or `null`
81+
Type: `function(error, fallbackNode)` or `null`
8282
Default: `null`
8383

8484
Parsing is tolerant by default, i.e. any text may to be parsed with no an raised exception. However, mistakes in CSS may make it imposible to parse some part, e.g. a selector or declaration. In that case bad content is wrapping into a `Raw` node and `onParseError` is invoking.
@@ -99,49 +99,49 @@ csstree.parse('example { foo; bar: 1! }', {
9999

100100
### onComment
101101

102-
Type: `function(value, loc)` or `null`
102+
Type: `function(value, loc)` or `null`
103103
Default: `null`
104104

105105
A handler to call for every comment in parsing source. Value is passing without surrounding `/*` and `*/`. [`loc`](ast.md#loc) will be `null` until `positions` option is set to `true`.
106106

107107
### onToken
108108

109-
Type: `function(type, start, end, index)` or `Array` or `null`
109+
Type: `function(type, start, end, index)` or `Array` or `null`
110110
Default: `null`
111111

112112
When a function, `onToken` is a handler to call for every token in the parsing source. The arguments are the numeric type of the token, the start offset, the end offset, and the token index. When an array, `onToken` is populated with objects containing the numeric type of the token (`type`), the start offset (`start`), and the end offset (`end`).
113113

114114
### filename
115115

116-
Type: `string`
116+
Type: `string`
117117
Default: `'<unknown>'`
118118

119119
Filename of source. This value adds to [`loc`](ast.md#loc) as `source` property when `positions` option is `true`. Using for source map generation.
120120

121121
### offset
122122

123-
Type: `number`
123+
Type: `number`
124124
Default: `0`
125125

126126
Start offset. Useful when parsing a fragment of CSS to store a correct positions for node's [`loc`](ast.md#loc) property.
127127

128128
### line
129129

130-
Type: `number`
130+
Type: `number`
131131
Default: `1`
132132

133133
Start line number. Useful when parsing fragment of CSS to store correct positions in node's [`loc`](ast.md#loc) property.
134134

135135
### column
136136

137-
Type: `number`
137+
Type: `number`
138138
Default: `1`
139139

140140
Start column number. Useful when parsing fragment of CSS to store correct positions in node's `loc` property.
141141

142142
### parseAtrulePrelude
143143

144-
Type: `boolean`
144+
Type: `boolean`
145145
Default: `true`
146146

147147
Defines to parse an at-rule prelude in details (represents as `AtruleExpresion`, `MediaQueryList` or `SelectorList` if any). Otherwise, represents prelude as `Raw` node.
@@ -187,7 +187,7 @@ csstree.parse('@example 1 2;', {
187187

188188
### parseRulePrelude
189189

190-
Type: `boolean`
190+
Type: `boolean`
191191
Default: `true`
192192

193193
Defines to parse a rule prelude in details or left unparsed (represents as `Raw` node).
@@ -241,7 +241,7 @@ csstree.parse('.foo {}', {
241241

242242
### parseValue
243243

244-
Type: `boolean`
244+
Type: `boolean`
245245
Default: `true`
246246

247247
Defines to parse a declaration value in details (represents as `Value`). Otherwise represents value as `Raw` node.
@@ -282,7 +282,7 @@ csstree.parse('color: #aabbcc', {
282282

283283
### parseCustomProperty
284284

285-
Type: `boolean`
285+
Type: `boolean`
286286
Default: `false`
287287

288288
Defines to parse a custom property value and a `var()` fallback in details (represents as `Value`). Otherwise represents value as `Raw` node.

0 commit comments

Comments
 (0)