.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / stylelint / lib / postcssPlugin.js
1 /* @flow */
2 "use strict";
3 /*:: type postcssType = {
4   atRule: Function,
5   comment: Function,
6   decl: Function,
7   list: any,
8   parse: any,
9   plugin: Function,
10   root: Function,
11   rule: Function,
12   stringify: any,
13   vendor: any,
14 } */
15 const _ = require("lodash");
16 const createStylelint = require("./createStylelint");
17 const path = require("path");
18 const postcss /*: postcssType*/ = require("postcss");
19 //'block-no-empty': bool || Array
20 /*:: type OptionsT = {
21   config?: {
22     extends?: Array<string>,
23     plugins?: Array<string>,
24     rules?: Object,
25   };
26   configBasedir?: string;
27   configFile?: string;
28   defaultSeverity?: string;
29   from?: string;
30   ignoreDisables?: boolean;
31   ignoreFiles?: string;
32   pluginFunctions?: Object;
33   plugins?: Array<string>;
34   rules?: Object;
35 }
36 */
37
38 /*:: type rootParamT = {
39   raws: {
40     semicolon: boolean,
41     after: string,
42   },
43   type: string,
44   nodes: Array<Object>,
45   source: {
46     input: {
47       css: string,
48       id?: string,
49       file?: string,
50     },
51     start: {
52       line: number,
53       column: number,
54     }
55   }
56 } */
57
58 /*:: type resultParamT = {
59   processor: {
60     version: string,
61     plugins: Array<Object>,
62   },
63   messages: Array<any>,
64   root: {
65     raws: {
66       semicolon: boolean,
67       after: string,
68     },
69     type: string,
70     nodes: Array<Object>,
71     source: {
72       input: Object,
73       start: Object,
74     },
75   },
76   opts: {
77     config?: {
78       rules: Object,
79     },
80     configFile?: string,
81     defaultSeverity?: string,
82     rules?: Object,
83     ignoreDisables?: boolean,
84     ignoreFiles?: string,
85     from?: string,
86     syntax?: {
87       parse: Function,
88       stringify: Function,
89     }
90   },
91   css: ?any,
92   map: ?any,
93   lastPlugin: {
94     postcssPlugin: string,
95     postcssVersion: string,
96   }
97 } */
98
99 /*:: type postcssPromise = Promise<?{ config: stylelint$config, filepath: string }>*/
100
101 module.exports = postcss.plugin("stylelint", function(
102   options /*: OptionsT*/
103 ) /*: Function*/ {
104   options = options || {};
105
106   const tailoredOptions /*: Object*/ = options.rules
107     ? { config: options }
108     : options;
109   const stylelint /*: stylelint$internalApi*/ = createStylelint(
110     tailoredOptions
111   );
112
113   // prettier-ignore
114   return (root/*: rootParamT*/, result/*: resultParamT*/)/*: Promise<any>*/ => {
115     let filePath = options.from || _.get(root, "source.input.file");
116     if (filePath !== undefined && !path.isAbsolute(filePath)) {
117       filePath = path.join(process.cwd(), filePath);
118     }
119
120     return stylelint._lintSource({
121       filePath,
122       existingPostcssResult: result
123     });
124   };
125 });