Skip to content

Commit dad9569

Browse files
committed
chore: migrate to eslint flat config
1 parent 2fbf3b4 commit dad9569

File tree

14 files changed

+4422
-2532
lines changed

14 files changed

+4422
-2532
lines changed

.eslintrc

Lines changed: 0 additions & 38 deletions
This file was deleted.

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CHANGELOG.md
2+
pnpm-lock.yaml
3+
example/*

README.md

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ npm i magic-string
2828
To use in browser, grab the [magic-string.umd.js](https://unpkg.com/magic-string/dist/magic-string.umd.js) file and add it to your page:
2929

3030
```html
31-
<script src='magic-string.umd.js'></script>
31+
<script src="magic-string.umd.js"></script>
3232
```
3333

3434
(It also works with various module systems, if you prefer that sort of thing - it has a dependency on [vlq](https://github.com/Rich-Harris/vlq).)
@@ -39,7 +39,7 @@ These examples assume you're in node.js, or something similar:
3939

4040
```js
4141
import MagicString from 'magic-string';
42-
import fs from 'fs'
42+
import fs from 'fs';
4343

4444
const s = new MagicString('problems = 99');
4545

@@ -53,9 +53,9 @@ s.prepend('var ').append(';'); // most methods are chainable
5353
s.toString(); // 'var answer = 42;'
5454

5555
const map = s.generateMap({
56-
source: 'source.js',
57-
file: 'converted.js.map',
58-
includeContent: true
56+
source: 'source.js',
57+
file: 'converted.js.map',
58+
includeContent: true,
5959
}); // generates a v3 sourcemap
6060

6161
fs.writeFileSync('converted.js', s.toString());
@@ -66,11 +66,13 @@ You can pass an options argument:
6666

6767
```js
6868
const s = new MagicString(someCode, {
69-
// these options will be used if you later call `bundle.addSource( s )` - see below
70-
filename: 'foo.js',
71-
indentExclusionRanges: [/*...*/],
72-
// mark source as ignore in DevTools, see below #Bundling
73-
ignoreList: false
69+
// these options will be used if you later call `bundle.addSource( s )` - see below
70+
filename: 'foo.js',
71+
indentExclusionRanges: [
72+
/*...*/
73+
],
74+
// mark source as ignore in DevTools, see below #Bundling
75+
ignoreList: false,
7476
});
7577
```
7678

@@ -86,11 +88,11 @@ Appends the specified content to the end of the string. Returns `this`.
8688

8789
### s.appendLeft( index, content )
8890

89-
Appends the specified `content` at the `index` in the original string. If a range *ending* with `index` is subsequently moved, the insert will be moved with it. Returns `this`. See also `s.prependLeft(...)`.
91+
Appends the specified `content` at the `index` in the original string. If a range _ending_ with `index` is subsequently moved, the insert will be moved with it. Returns `this`. See also `s.prependLeft(...)`.
9092

9193
### s.appendRight( index, content )
9294

93-
Appends the specified `content` at the `index` in the original string. If a range *starting* with `index` is subsequently moved, the insert will be moved with it. Returns `this`. See also `s.prependRight(...)`.
95+
Appends the specified `content` at the `index` in the original string. If a range _starting_ with `index` is subsequently moved, the insert will be moved with it. Returns `this`. See also `s.prependRight(...)`.
9496

9597
### s.clone()
9698

@@ -104,15 +106,15 @@ Generates a sourcemap object with raw mappings in array form, rather than encode
104106

105107
Generates a [version 3 sourcemap](https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit). All options are, well, optional:
106108

107-
* `file` - the filename where you plan to write the sourcemap
108-
* `source` - the filename of the file containing the original source
109-
* `includeContent` - whether to include the original content in the map's `sourcesContent` array
110-
* `hires` - whether the mapping should be high-resolution. Hi-res mappings map every single character, meaning (for example) your devtools will always be able to pinpoint the exact location of function calls and so on. With lo-res mappings, devtools may only be able to identify the correct line - but they're quicker to generate and less bulky. You can also set `"boundary"` to generate a semi-hi-res mappings segmented per word boundary instead of per character, suitable for string semantics that are separated by words. If sourcemap locations have been specified with `s.addSourcemapLocation()`, they will be used here.
109+
- `file` - the filename where you plan to write the sourcemap
110+
- `source` - the filename of the file containing the original source
111+
- `includeContent` - whether to include the original content in the map's `sourcesContent` array
112+
- `hires` - whether the mapping should be high-resolution. Hi-res mappings map every single character, meaning (for example) your devtools will always be able to pinpoint the exact location of function calls and so on. With lo-res mappings, devtools may only be able to identify the correct line - but they're quicker to generate and less bulky. You can also set `"boundary"` to generate a semi-hi-res mappings segmented per word boundary instead of per character, suitable for string semantics that are separated by words. If sourcemap locations have been specified with `s.addSourcemapLocation()`, they will be used here.
111113

112114
The returned sourcemap has two (non-enumerable) methods attached for convenience:
113115

114-
* `toString` - returns the equivalent of `JSON.stringify(map)`
115-
* `toUrl` - returns a DataURI containing the sourcemap. Useful for doing this sort of thing:
116+
- `toString` - returns the equivalent of `JSON.stringify(map)`
117+
- `toUrl` - returns a DataURI containing the sourcemap. Useful for doing this sort of thing:
116118

117119
```js
118120
code += '\n//# sourceMappingURL=' + map.toUrl();
@@ -166,27 +168,28 @@ Prepends the string with the specified content. Returns `this`.
166168

167169
### s.prependLeft ( index, content )
168170

169-
Same as `s.appendLeft(...)`, except that the inserted content will go *before* any previous appends or prepends at `index`
171+
Same as `s.appendLeft(...)`, except that the inserted content will go _before_ any previous appends or prepends at `index`
170172

171173
### s.prependRight ( index, content )
172174

173-
Same as `s.appendRight(...)`, except that the inserted content will go *before* any previous appends or prepends at `index`
175+
Same as `s.appendRight(...)`, except that the inserted content will go _before_ any previous appends or prepends at `index`
174176

175177
### s.replace( regexpOrString, substitution )
176178

177179
String replacement with RegExp or string. When using a RegExp, replacer function is also supported. Returns `this`.
178180

179181
```ts
180-
import MagicString from 'magic-string'
182+
import MagicString from 'magic-string';
181183

182-
const s = new MagicString(source)
184+
const s = new MagicString(source);
183185

184-
s.replace('foo', 'bar')
185-
s.replace(/foo/g, 'bar')
186-
s.replace(/(\w)(\d+)/g, (_, $1, $2) => $1.toUpperCase() + $2)
186+
s.replace('foo', 'bar');
187+
s.replace(/foo/g, 'bar');
188+
s.replace(/(\w)(\d+)/g, (_, $1, $2) => $1.toUpperCase() + $2);
187189
```
188190

189-
The differences from [`String.replace`]((https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)):
191+
The differences from [`String.replace`](<(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)>):
192+
190193
- It will always match against the **original string**
191194
- It mutates the magic string state (use `.clone()` to be immutable)
192195

@@ -248,31 +251,32 @@ To concatenate several sources, use `MagicString.Bundle`:
248251
const bundle = new MagicString.Bundle();
249252

250253
bundle.addSource({
251-
filename: 'foo.js',
252-
content: new MagicString('var answer = 42;')
254+
filename: 'foo.js',
255+
content: new MagicString('var answer = 42;'),
253256
});
254257

255258
bundle.addSource({
256-
filename: 'bar.js',
257-
content: new MagicString('console.log( answer )')
259+
filename: 'bar.js',
260+
content: new MagicString('console.log( answer )'),
258261
});
259262

260263
// Sources can be marked as ignore-listed, which provides a hint to debuggers
261264
// to not step into this code and also don't show the source files depending
262265
// on user preferences.
263266
bundle.addSource({
264-
filename: 'some-3rdparty-library.js',
265-
content: new MagicString('function myLib(){}'),
266-
ignoreList: false // <--
267-
})
267+
filename: 'some-3rdparty-library.js',
268+
content: new MagicString('function myLib(){}'),
269+
ignoreList: false, // <--
270+
});
268271

269272
// Advanced: a source can include an `indentExclusionRanges` property
270273
// alongside `filename` and `content`. This will be passed to `s.indent()`
271274
// - see documentation above
272275

273-
bundle.indent() // optionally, pass an indent string, otherwise it will be guessed
274-
.prepend('(function () {\n')
275-
.append('}());');
276+
bundle
277+
.indent() // optionally, pass an indent string, otherwise it will be guessed
278+
.prepend('(function () {\n')
279+
.append('}());');
276280

277281
bundle.toString();
278282
// (function () {
@@ -282,9 +286,9 @@ bundle.toString();
282286

283287
// options are as per `s.generateMap()` above
284288
const map = bundle.generateMap({
285-
file: 'bundle.js',
286-
includeContent: true,
287-
hires: true
289+
file: 'bundle.js',
290+
includeContent: true,
291+
hires: true,
288292
});
289293
```
290294

@@ -293,7 +297,7 @@ As an alternative syntax, if you a) don't have `filename` or `indentExclusionRan
293297
```js
294298
const bundle = new MagicString.Bundle();
295299
const source = new MagicString(someCode, {
296-
filename: 'foo.js'
300+
filename: 'foo.js',
297301
});
298302

299303
bundle.addSource(source);

0 commit comments

Comments
 (0)