mirror of
https://github.com/hanzoai/postcss.git
synced 2026-09-24 17:01:56 +00:00
Sort source code and fix ESLint
This commit is contained in:
+14
-3
@@ -1,6 +1,5 @@
|
||||
import loguxTsConfig from '@logux/eslint-config/ts'
|
||||
|
||||
/** @type {import('eslint').Linter.FlatConfig[]} */
|
||||
export default [
|
||||
{ ignores: ['docs/api/assets/', '**/errors.ts'] },
|
||||
...loguxTsConfig,
|
||||
@@ -10,13 +9,24 @@ export default [
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
'consistent-return': 'off',
|
||||
'global-require': 'off',
|
||||
'node-import/prefer-node-protocol': 'off'
|
||||
'n/no-unsupported-features/es-syntax': [
|
||||
'error',
|
||||
{
|
||||
ignores: ['hashbang', 'modules']
|
||||
}
|
||||
],
|
||||
'n/no-unsupported-features/node-builtins': [
|
||||
'error',
|
||||
{ ignores: ['url.fileURLToPath', 'url.pathToFileURL', 'btoa', 'atob'] }
|
||||
],
|
||||
'n/prefer-node-protocol': 'off'
|
||||
}
|
||||
},
|
||||
{
|
||||
files: ['**/*.d.ts'],
|
||||
rules: {
|
||||
'@typescript-eslint/no-redeclare': 'off'
|
||||
'@typescript-eslint/no-redeclare': 'off',
|
||||
'n/no-unsupported-features/es-syntax': 'off'
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -25,6 +35,7 @@ export default [
|
||||
'@typescript-eslint/no-unused-expressions': 'off',
|
||||
'func-style': 'off',
|
||||
'n/no-unsupported-features/es-syntax': 'off',
|
||||
'n/no-unsupported-features/node-builtins': 'off',
|
||||
'no-console': 'off',
|
||||
'no-unused-expressions': 'off'
|
||||
}
|
||||
|
||||
Vendored
+28
-28
@@ -20,11 +20,11 @@ declare namespace Container {
|
||||
/**
|
||||
* An array of property names.
|
||||
*/
|
||||
props?: ReadonlyArray<string>
|
||||
props?: readonly string[]
|
||||
}
|
||||
|
||||
export interface ContainerProps extends NodeProps {
|
||||
nodes?: ReadonlyArray<Node | ChildProps>
|
||||
nodes?: readonly (ChildProps | Node)[]
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -33,11 +33,11 @@ declare namespace Container {
|
||||
*/
|
||||
export type NewChild =
|
||||
| ChildProps
|
||||
| ReadonlyArray<ChildProps>
|
||||
| Node
|
||||
| ReadonlyArray<Node>
|
||||
| readonly ChildProps[]
|
||||
| readonly Node[]
|
||||
| readonly string[]
|
||||
| string
|
||||
| ReadonlyArray<string>
|
||||
| undefined
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
||||
@@ -64,6 +64,26 @@ declare abstract class Container_<Child extends Node = ChildNode> extends Node {
|
||||
*/
|
||||
nodes: Child[] | undefined
|
||||
|
||||
/**
|
||||
* An internal method that converts a {@link NewChild} into a list of actual
|
||||
* child nodes that can then be added to this container.
|
||||
*
|
||||
* This ensures that the nodes' parent is set to this container, that they use
|
||||
* the correct prototype chain, and that they're marked as dirty.
|
||||
*
|
||||
* @param mnodes The new node or nodes to add.
|
||||
* @param sample A node from whose raws the new node's `before` raw should be
|
||||
* taken.
|
||||
* @param type This should be set to `'prepend'` if the new nodes will be
|
||||
* inserted at the beginning of the container.
|
||||
* @hidden
|
||||
*/
|
||||
protected normalize(
|
||||
nodes: Container.NewChild,
|
||||
sample: Node | undefined,
|
||||
type?: 'prepend' | false
|
||||
): Child[]
|
||||
|
||||
/**
|
||||
* Inserts new nodes to the end of the container.
|
||||
*
|
||||
@@ -85,10 +105,10 @@ declare abstract class Container_<Child extends Node = ChildNode> extends Node {
|
||||
* @return This node for methods chain.
|
||||
*/
|
||||
append(...nodes: Container.NewChild[]): this
|
||||
|
||||
assign(overrides: Container.ContainerProps | object): this
|
||||
clone(overrides?: Partial<Container.ContainerProps>): this
|
||||
cloneAfter(overrides?: Partial<Container.ContainerProps>): this
|
||||
|
||||
cloneBefore(overrides?: Partial<Container.ContainerProps>): this
|
||||
|
||||
/**
|
||||
@@ -127,7 +147,6 @@ declare abstract class Container_<Child extends Node = ChildNode> extends Node {
|
||||
each(
|
||||
callback: (node: Child, index: number) => false | void
|
||||
): false | undefined
|
||||
|
||||
/**
|
||||
* Returns `true` if callback returns `true`
|
||||
* for all of the container’s children.
|
||||
@@ -142,6 +161,7 @@ declare abstract class Container_<Child extends Node = ChildNode> extends Node {
|
||||
every(
|
||||
condition: (node: Child, index: number, nodes: Child[]) => boolean
|
||||
): boolean
|
||||
|
||||
/**
|
||||
* Returns a `child`’s index within the `Container#nodes` array.
|
||||
*
|
||||
@@ -153,7 +173,6 @@ declare abstract class Container_<Child extends Node = ChildNode> extends Node {
|
||||
* @return Child index.
|
||||
*/
|
||||
index(child: Child | number): number
|
||||
|
||||
/**
|
||||
* Insert new node after old node within the container.
|
||||
*
|
||||
@@ -162,6 +181,7 @@ declare abstract class Container_<Child extends Node = ChildNode> extends Node {
|
||||
* @return This node for methods chain.
|
||||
*/
|
||||
insertAfter(oldNode: Child | number, newNode: Container.NewChild): this
|
||||
|
||||
/**
|
||||
* Insert new node before old node within the container.
|
||||
*
|
||||
@@ -175,26 +195,6 @@ declare abstract class Container_<Child extends Node = ChildNode> extends Node {
|
||||
*/
|
||||
insertBefore(oldNode: Child | number, newNode: Container.NewChild): this
|
||||
|
||||
/**
|
||||
* An internal method that converts a {@link NewChild} into a list of actual
|
||||
* child nodes that can then be added to this container.
|
||||
*
|
||||
* This ensures that the nodes' parent is set to this container, that they use
|
||||
* the correct prototype chain, and that they're marked as dirty.
|
||||
*
|
||||
* @param mnodes The new node or nodes to add.
|
||||
* @param sample A node from whose raws the new node's `before` raw should be
|
||||
* taken.
|
||||
* @param type This should be set to `'prepend'` if the new nodes will be
|
||||
* inserted at the beginning of the container.
|
||||
* @hidden
|
||||
*/
|
||||
protected normalize(
|
||||
nodes: Container.NewChild,
|
||||
sample: Node | undefined,
|
||||
type?: 'prepend' | false
|
||||
): Child[]
|
||||
|
||||
/**
|
||||
* Traverses the container’s descendant nodes, calling callback
|
||||
* for each comment node.
|
||||
|
||||
+3
-3
@@ -1,11 +1,11 @@
|
||||
'use strict'
|
||||
|
||||
let { isClean, my } = require('./symbols')
|
||||
let Declaration = require('./declaration')
|
||||
let Comment = require('./comment')
|
||||
let Declaration = require('./declaration')
|
||||
let Node = require('./node')
|
||||
let { isClean, my } = require('./symbols')
|
||||
|
||||
let parse, Rule, AtRule, Root
|
||||
let AtRule, parse, Root, Rule
|
||||
|
||||
function cleanSource(nodes) {
|
||||
return nodes.map(i => {
|
||||
|
||||
Vendored
+1
-1
@@ -5,7 +5,7 @@ import Root from './root.js'
|
||||
|
||||
declare namespace Document {
|
||||
export interface DocumentProps extends ContainerProps {
|
||||
nodes?: ReadonlyArray<Root>
|
||||
nodes?: readonly Root[]
|
||||
|
||||
/**
|
||||
* Information to generate byte-to-byte equal node string as it was
|
||||
|
||||
+3
-3
@@ -1,10 +1,10 @@
|
||||
'use strict'
|
||||
|
||||
let Declaration = require('./declaration')
|
||||
let PreviousMap = require('./previous-map')
|
||||
let Comment = require('./comment')
|
||||
let AtRule = require('./at-rule')
|
||||
let Comment = require('./comment')
|
||||
let Declaration = require('./declaration')
|
||||
let Input = require('./input')
|
||||
let PreviousMap = require('./previous-map')
|
||||
let Root = require('./root')
|
||||
let Rule = require('./rule')
|
||||
|
||||
|
||||
Vendored
+3
-3
@@ -174,6 +174,9 @@ declare class Input_ {
|
||||
endLine?: number,
|
||||
endColumn?: number
|
||||
): false | Input.FilePosition
|
||||
/** Converts this to a JSON-friendly object representation. */
|
||||
toJSON(): object
|
||||
|
||||
/**
|
||||
* The CSS source identifier. Contains `Input#file` if the user
|
||||
* set the `from` option, or `Input#id` if they did not.
|
||||
@@ -187,9 +190,6 @@ declare class Input_ {
|
||||
* ```
|
||||
*/
|
||||
get from(): string
|
||||
|
||||
/** Converts this to a JSON-friendly object representation. */
|
||||
toJSON(): object
|
||||
}
|
||||
|
||||
declare class Input extends Input_ {}
|
||||
|
||||
+4
-4
@@ -1,13 +1,13 @@
|
||||
'use strict'
|
||||
|
||||
let { nanoid } = require('nanoid/non-secure')
|
||||
let { isAbsolute, resolve } = require('path')
|
||||
let { SourceMapConsumer, SourceMapGenerator } = require('source-map-js')
|
||||
let { fileURLToPath, pathToFileURL } = require('url')
|
||||
let { isAbsolute, resolve } = require('path')
|
||||
let { nanoid } = require('nanoid/non-secure')
|
||||
|
||||
let terminalHighlight = require('./terminal-highlight')
|
||||
let CssSyntaxError = require('./css-syntax-error')
|
||||
let PreviousMap = require('./previous-map')
|
||||
let terminalHighlight = require('./terminal-highlight')
|
||||
|
||||
let fromOffsetCache = Symbol('fromOffsetCache')
|
||||
|
||||
@@ -61,7 +61,7 @@ class Input {
|
||||
}
|
||||
|
||||
error(message, line, column, opts = {}) {
|
||||
let result, endLine, endColumn
|
||||
let endColumn, endLine, result
|
||||
|
||||
if (line && typeof line === 'object') {
|
||||
let start = line
|
||||
|
||||
+5
-5
@@ -1,14 +1,14 @@
|
||||
'use strict'
|
||||
|
||||
let { isClean, my } = require('./symbols')
|
||||
let MapGenerator = require('./map-generator')
|
||||
let stringify = require('./stringify')
|
||||
let Container = require('./container')
|
||||
let Document = require('./document')
|
||||
let warnOnce = require('./warn-once')
|
||||
let Result = require('./result')
|
||||
let MapGenerator = require('./map-generator')
|
||||
let parse = require('./parse')
|
||||
let Result = require('./result')
|
||||
let Root = require('./root')
|
||||
let stringify = require('./stringify')
|
||||
let { isClean, my } = require('./symbols')
|
||||
let warnOnce = require('./warn-once')
|
||||
|
||||
const TYPE_TO_CLASS_NAME = {
|
||||
atrule: 'AtRule',
|
||||
|
||||
Vendored
+1
-1
@@ -49,7 +49,7 @@ declare namespace list {
|
||||
*/
|
||||
split(
|
||||
string: string,
|
||||
separators: ReadonlyArray<string>,
|
||||
separators: readonly string[],
|
||||
last: boolean
|
||||
): string[]
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use strict'
|
||||
|
||||
let { SourceMapConsumer, SourceMapGenerator } = require('source-map-js')
|
||||
let { dirname, relative, resolve, sep } = require('path')
|
||||
let { SourceMapConsumer, SourceMapGenerator } = require('source-map-js')
|
||||
let { pathToFileURL } = require('url')
|
||||
|
||||
let Input = require('./input')
|
||||
@@ -143,7 +143,7 @@ class MapGenerator {
|
||||
source: ''
|
||||
}
|
||||
|
||||
let lines, last
|
||||
let last, lines
|
||||
this.stringify(this.root, (str, node, type) => {
|
||||
this.css += str
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
'use strict'
|
||||
|
||||
let MapGenerator = require('./map-generator')
|
||||
let stringify = require('./stringify')
|
||||
let warnOnce = require('./warn-once')
|
||||
let parse = require('./parse')
|
||||
const Result = require('./result')
|
||||
let stringify = require('./stringify')
|
||||
let warnOnce = require('./warn-once')
|
||||
|
||||
class NoWorkResult {
|
||||
constructor(processor, css, opts) {
|
||||
|
||||
Vendored
+10
-10
@@ -234,6 +234,14 @@ declare abstract class Node_ {
|
||||
|
||||
constructor(defaults?: object)
|
||||
|
||||
/**
|
||||
* If this node isn't already dirty, marks it and its ancestors as such. This
|
||||
* indicates to the LazyResult processor that the {@link Root} has been
|
||||
* modified by the current plugin and may need to be processed again by other
|
||||
* plugins.
|
||||
*/
|
||||
protected markDirty(): void
|
||||
|
||||
/**
|
||||
* Insert new node after current node to current node’s parent.
|
||||
*
|
||||
@@ -247,7 +255,7 @@ declare abstract class Node_ {
|
||||
* @return This node for methods chain.
|
||||
*/
|
||||
after(
|
||||
newNode: Node | Node.ChildProps | ReadonlyArray<Node> | string | undefined
|
||||
newNode: Node | Node.ChildProps | readonly Node[] | string | undefined
|
||||
): this
|
||||
|
||||
/**
|
||||
@@ -276,7 +284,7 @@ declare abstract class Node_ {
|
||||
* @return This node for methods chain.
|
||||
*/
|
||||
before(
|
||||
newNode: Node | Node.ChildProps | ReadonlyArray<Node> | string | undefined
|
||||
newNode: Node | Node.ChildProps | readonly Node[] | string | undefined
|
||||
): this
|
||||
|
||||
/**
|
||||
@@ -368,14 +376,6 @@ declare abstract class Node_ {
|
||||
*/
|
||||
error(message: string, options?: Node.NodeErrorOptions): CssSyntaxError
|
||||
|
||||
/**
|
||||
* If this node isn't already dirty, marks it and its ancestors as such. This
|
||||
* indicates to the LazyResult processor that the {@link Root} has been
|
||||
* modified by the current plugin and may need to be processed again by other
|
||||
* plugins.
|
||||
*/
|
||||
protected markDirty(): void
|
||||
|
||||
/**
|
||||
* Returns the next child of the node’s parent.
|
||||
* Returns `undefined` if the current node is the last child.
|
||||
|
||||
+1
-1
@@ -1,9 +1,9 @@
|
||||
'use strict'
|
||||
|
||||
let { isClean, my } = require('./symbols')
|
||||
let CssSyntaxError = require('./css-syntax-error')
|
||||
let Stringifier = require('./stringifier')
|
||||
let stringify = require('./stringify')
|
||||
let { isClean, my } = require('./symbols')
|
||||
|
||||
function cloneNode(obj, parent) {
|
||||
let cloned = new obj.constructor()
|
||||
|
||||
+1
-1
@@ -1,8 +1,8 @@
|
||||
'use strict'
|
||||
|
||||
let Container = require('./container')
|
||||
let Parser = require('./parser')
|
||||
let Input = require('./input')
|
||||
let Parser = require('./parser')
|
||||
|
||||
function parse(css, opts) {
|
||||
let input = new Input(css, opts)
|
||||
|
||||
+4
-4
@@ -1,11 +1,11 @@
|
||||
'use strict'
|
||||
|
||||
let Declaration = require('./declaration')
|
||||
let tokenizer = require('./tokenize')
|
||||
let Comment = require('./comment')
|
||||
let AtRule = require('./at-rule')
|
||||
let Comment = require('./comment')
|
||||
let Declaration = require('./declaration')
|
||||
let Root = require('./root')
|
||||
let Rule = require('./rule')
|
||||
let tokenizer = require('./tokenize')
|
||||
|
||||
const SAFE_COMMENT_NEIGHBOR = {
|
||||
empty: true,
|
||||
@@ -143,7 +143,7 @@ class Parser {
|
||||
|
||||
colon(tokens) {
|
||||
let brackets = 0
|
||||
let token, type, prev
|
||||
let prev, token, type
|
||||
for (let [i, element] of tokens.entries()) {
|
||||
token = element
|
||||
type = token[0]
|
||||
|
||||
Vendored
+1
-1
@@ -446,7 +446,7 @@ declare namespace postcss {
|
||||
* @return Processor to process multiple CSS.
|
||||
*/
|
||||
declare function postcss(
|
||||
plugins?: ReadonlyArray<postcss.AcceptedPlugin>
|
||||
plugins?: readonly postcss.AcceptedPlugin[]
|
||||
): Processor
|
||||
declare function postcss(...plugins: postcss.AcceptedPlugin[]): Processor
|
||||
|
||||
|
||||
+12
-12
@@ -1,23 +1,23 @@
|
||||
'use strict'
|
||||
|
||||
let AtRule = require('./at-rule')
|
||||
let Comment = require('./comment')
|
||||
let Container = require('./container')
|
||||
let CssSyntaxError = require('./css-syntax-error')
|
||||
let Declaration = require('./declaration')
|
||||
let LazyResult = require('./lazy-result')
|
||||
let Container = require('./container')
|
||||
let Processor = require('./processor')
|
||||
let stringify = require('./stringify')
|
||||
let fromJSON = require('./fromJSON')
|
||||
let Document = require('./document')
|
||||
let Warning = require('./warning')
|
||||
let Comment = require('./comment')
|
||||
let AtRule = require('./at-rule')
|
||||
let Result = require('./result.js')
|
||||
let fromJSON = require('./fromJSON')
|
||||
let Input = require('./input')
|
||||
let parse = require('./parse')
|
||||
let LazyResult = require('./lazy-result')
|
||||
let list = require('./list')
|
||||
let Rule = require('./rule')
|
||||
let Root = require('./root')
|
||||
let Node = require('./node')
|
||||
let parse = require('./parse')
|
||||
let Processor = require('./processor')
|
||||
let Result = require('./result.js')
|
||||
let Root = require('./root')
|
||||
let Rule = require('./rule')
|
||||
let stringify = require('./stringify')
|
||||
let Warning = require('./warning')
|
||||
|
||||
function postcss(...plugins) {
|
||||
if (plugins.length === 1 && Array.isArray(plugins[0])) {
|
||||
|
||||
+1
-1
@@ -1,8 +1,8 @@
|
||||
'use strict'
|
||||
|
||||
let { SourceMapConsumer, SourceMapGenerator } = require('source-map-js')
|
||||
let { existsSync, readFileSync } = require('fs')
|
||||
let { dirname, join } = require('path')
|
||||
let { SourceMapConsumer, SourceMapGenerator } = require('source-map-js')
|
||||
|
||||
function fromBase64(str) {
|
||||
if (Buffer) {
|
||||
|
||||
Vendored
+1
-1
@@ -51,7 +51,7 @@ declare class Processor_ {
|
||||
/**
|
||||
* @param plugins PostCSS plugins
|
||||
*/
|
||||
constructor(plugins?: ReadonlyArray<AcceptedPlugin>)
|
||||
constructor(plugins?: readonly AcceptedPlugin[])
|
||||
|
||||
/**
|
||||
* Parses source CSS and returns a `LazyResult` Promise proxy.
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
'use strict'
|
||||
|
||||
let NoWorkResult = require('./no-work-result')
|
||||
let LazyResult = require('./lazy-result')
|
||||
let Document = require('./document')
|
||||
let LazyResult = require('./lazy-result')
|
||||
let NoWorkResult = require('./no-work-result')
|
||||
let Root = require('./root')
|
||||
|
||||
class Processor {
|
||||
|
||||
Vendored
+4
-4
@@ -40,7 +40,7 @@ declare namespace Rule {
|
||||
semicolon?: boolean
|
||||
}
|
||||
|
||||
export type RuleProps = ContainerProps & {
|
||||
export type RuleProps = {
|
||||
/** Information used to generate byte-to-byte equal node string as it was in the origin input. */
|
||||
raws?: RuleRaws
|
||||
} & (
|
||||
@@ -50,11 +50,11 @@ declare namespace Rule {
|
||||
selectors?: never
|
||||
}
|
||||
| {
|
||||
/** Selectors of the rule represented as an array of strings. */
|
||||
selectors: ReadonlyArray<string>
|
||||
selector?: never
|
||||
/** Selectors of the rule represented as an array of strings. */
|
||||
selectors: readonly string[]
|
||||
}
|
||||
)
|
||||
) & ContainerProps
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
||||
export { Rule_ as default }
|
||||
|
||||
+2
-2
@@ -29,8 +29,8 @@ module.exports = function tokenizer(input, options = {}) {
|
||||
let css = input.css.valueOf()
|
||||
let ignore = options.ignoreErrors
|
||||
|
||||
let code, next, quote, content, escape
|
||||
let escaped, escapePos, prev, n, currentToken
|
||||
let code, content, escape, next, quote
|
||||
let currentToken, escaped, escapePos, n, prev
|
||||
|
||||
let length = css.length
|
||||
let pos = 0
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
let { test } = require('uvu')
|
||||
let { equal, is, throws } = require('uvu/assert')
|
||||
|
||||
let tokenizer = require('../lib/tokenize')
|
||||
let { Input } = require('../lib/postcss')
|
||||
let tokenizer = require('../lib/tokenize')
|
||||
|
||||
function tokenize(css, opts) {
|
||||
let processor = tokenizer(new Input(css), opts)
|
||||
|
||||
@@ -87,7 +87,7 @@ test('gets range from node without end', () => {
|
||||
|
||||
test('gets range from node with endIndex 3', () => {
|
||||
let root = parse('a{}')
|
||||
let warning = new Warning('text', { node: root.first, index: 0, endIndex: 3 })
|
||||
let warning = new Warning('text', { endIndex: 3, index: 0, node: root.first })
|
||||
is(warning.line, 1)
|
||||
is(warning.column, 1)
|
||||
is(warning.endLine, 1)
|
||||
@@ -96,7 +96,7 @@ test('gets range from node with endIndex 3', () => {
|
||||
|
||||
test('gets range from node with endIndex 0', () => {
|
||||
let root = parse('a{}')
|
||||
let warning = new Warning('text', { node: root.first, index: 0, endIndex: 0 })
|
||||
let warning = new Warning('text', { endIndex: 0, index: 0, node: root.first })
|
||||
is(warning.line, 1)
|
||||
is(warning.column, 1)
|
||||
is(warning.endLine, 1)
|
||||
|
||||
Reference in New Issue
Block a user