added all files to project

This commit is contained in:
2022-03-10 10:36:59 +01:00
parent 09dd957b33
commit 46a936d7de
25351 changed files with 3883356 additions and 0 deletions
+77
View File
@@ -0,0 +1,77 @@
# Changelog
## 1.2.0 (2021-02-27)
- Do not trigger prettier for .svelte and .component.html (angular) files. This avoids errors. Prettifying a subset of the file (i.e. just contents of `<style>` tags) using stylelint feels like unneeded work if you're about to run prettier over the whole file anyway (#160)
## 1.1.2 (2019-12-14)
- Account for user defined parser overrides when working out what files to skip (#39)
- Add an extra check to quickly skip formatting CSS-in-JS object literals (#39)
- Bump dev dependencies (#39)
## 1.1.1 (2019-05-30)
- Fix incorrect trailing whitespace on Windows (#24)
## 1.1.0 (2019-05-12)
- Do not trigger prettier for js, ts, vue, html and markdown files. In stylelint >=9.9.0 these files sometimes worked and sometimes threw errors. In stylelint >=9.10.0 they would either error or have incorrect indentation. Prettifying a subset of the file (i.e. just contents of `<style>` tags) using stylelint feels like unneeded work if you're about to run prettier over the whole file anyway (#22)
## 1.0.7 (2019-05-07)
- Add stylelint >9.2.1 as a peerDependency to help Yarn PNP support
## 1.0.6 (2019-01-05)
- Report unparsable code as linting issues instead of crashing (#14)
## 1.0.5 (2018-11-16)
- Specifying an explict syntax with `--syntax` will no longer crash when autofixing (#11)
## 1.0.4 (2018-11-11)
- Do not pass stylelint built-in options `severity` and `messsage` to prettier (#10)
## 1.0.3 (2018-10-01)
- Use the CSS parser when no filename is specified
- Use prettier-linter-helpers instead of depending on eslint-plugin-prettier (#7)
## 1.0.2 (2018-09-28)
- Update documentation and package.json to reflect the new repo location as part of the prettier GitHub organization (#5)
## 1.0.1 (2018-09-05)
- Allow using overrides in `.prettierrc` to lint non-standard file extensions (#3)
## 1.0.0 (2018-09-05)
The code for v1.0.0 is identical to v0.2.2. It has been used in production for a
little while and I consider it stable.
- Minor readme tweaks
## 0.2.2 (2018-07-29)
- Better formatting of `\r` in reporting
- Bump minimum required eslint-plugin-prettier version to 2.6.2
- Ignore files that are specified in a .prettierignore file
## 0.2.1 (2018-07-03)
- Ensure non-css languages (e.g. scss) would be parsed correctly when autofixing
- Bump minimum required stylelint version to 9.2.1
- Ensure trailing whitespace is always output when autofixing, even if the input file lacked trailing whitespace
## 0.2.0 (2018-07-02)
- Add support for autofixing issues using `stylelint --fix`
## 0.1.0 (2018-07-02)
- Initial functionality
- Exposes a stylelint plugin that runs prettier
- It reads config from .prettierrc by default but you can also pass config options into the rule
+24
View File
@@ -0,0 +1,24 @@
# The MIT License (MIT)
Copyright © 2018 Ben Scott
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the “Software”), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
+109
View File
@@ -0,0 +1,109 @@
# stylelint-prettier [![Build Status](https://github.com/prettier/stylelint-prettier/workflows/CI/badge.svg?branch=master)](https://github.com/prettier/stylelint-prettier/actions?query=workflow%3ACI+branch%3Amaster)
Runs [Prettier](https://github.com/prettier/prettier) as a [Stylelint](https://stylelint.io/) rule and reports differences as individual Stylelint issues.
## Sample
Given the input file `style.css`:
<!-- prettier-ignore -->
```css
.insert {
display: block
}
.alter:after {color: red; content: 'example'}
.delete {
display: block;;
}
```
Running `./node_modules/.bin/stylelint style.css` shall output:
```
style.css
2:17 ✖ Insert ";" prettier/prettier
5:15 ✖ Replace "color:·red;·content:·'example'" with prettier/prettier
"⏎··color:·red;⏎··content:·"example";⏎"
8:17 ✖ Delete ";" prettier/prettier
```
## Installation
```sh
npm install --save-dev stylelint-prettier prettier
```
**_`stylelint-prettier` does not install Prettier or Stylelint for you._** _You must install these yourself._
Then, in your `.stylelintrc`:
```json
{
"plugins": ["stylelint-prettier"],
"rules": {
"prettier/prettier": true
}
}
```
## Recommended Configuration
This plugin works best if you disable all other Stylelint rules relating to code formatting, and only enable rules that detect patterns in the AST. (If another active Stylelint rule disagrees with `prettier` about how code should be formatted, it will be impossible to avoid lint errors.) You can use [stylelint-config-prettier](https://github.com/prettier/stylelint-config-prettier) to disable all formatting-related Stylelint rules.
If your desired formatting does not match the `prettier` output, you should use a different tool such as [prettier-stylelint](https://github.com/hugomrdias/prettier-stylelint) instead.
To integrate this plugin with `stylelint-config-prettier`, you can use the `"recommended"` configuration:
1. In addition to the above installation instructions, install `stylelint-config-prettier`:
```sh
npm install --save-dev stylelint-config-prettier
```
2. Then replace the plugins and rules declarations in your `.stylelintrc` that you added in the prior section with:
```json
{
"extends": ["stylelint-prettier/recommended"]
}
```
This does three things:
1. Enables the `stylelint-plugin-prettier` plugin.
2. Enables the `prettier/prettier` rule.
3. Extends the `stylelint-config-prettier` configuration.
You can then set Prettier's own options inside a `.prettierrc` file.
## Options
_stylelint-prettier will honor your `.prettierrc` file by default_. You only
need this section if you wish to override those settings.
> Note: While it is possible to pass options to Prettier via your Stylelint configuration file, it is not recommended because editor extensions such as `prettier-atom` and `prettier-vscode` **will** read [`.prettierrc`](https://prettier.io/docs/en/configuration.html), but **won't** read settings from Stylelint, which can lead to an inconsistent experience.
Objects are passed directly to Prettier as [options](https://prettier.io/docs/en/options.html). Example:
```json
{
"rules": {
"prettier/prettier": [true, {"singleQuote": true, "tabWidth": 4}]
}
}
```
NB: This option will merge and override any config set with `.prettierrc` files (for Prettier < 1.7.0, config files are ignored)
---
## Contributing
See [CONTRIBUTING.md](https://github.com/prettier/stylelint-prettier/blob/master/.github/CONTRIBUTING.md)
## Inspiration
The layout for this codebase and base configuration of prettier was taken from <https://github.com/prettier/eslint-plugin-prettier>
+91
View File
@@ -0,0 +1,91 @@
{
"_args": [
[
"stylelint-prettier@1.2.0",
"/home/pi/Desktop/smartMirrorTestEnvironment/MagicMirror"
]
],
"_development": true,
"_from": "stylelint-prettier@1.2.0",
"_id": "stylelint-prettier@1.2.0",
"_inBundle": false,
"_integrity": "sha512-/MYz6W2CNgKHblPzPtk7cybu8H5dGG3c2GevL64RButERj1uJg4SdBIIat1hMfDOmN6QQpldc6tCc//ZAWh9WQ==",
"_location": "/stylelint-prettier",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "stylelint-prettier@1.2.0",
"name": "stylelint-prettier",
"escapedName": "stylelint-prettier",
"rawSpec": "1.2.0",
"saveSpec": null,
"fetchSpec": "1.2.0"
},
"_requiredBy": [
"#DEV:/"
],
"_resolved": "https://registry.npmjs.org/stylelint-prettier/-/stylelint-prettier-1.2.0.tgz",
"_spec": "1.2.0",
"_where": "/home/pi/Desktop/smartMirrorTestEnvironment/MagicMirror",
"author": {
"name": "Ben Scott"
},
"bugs": {
"url": "https://github.com/prettier/stylelint-prettier/issues"
},
"dependencies": {
"prettier-linter-helpers": "^1.0.0"
},
"description": "Runs prettier as an stylelint rule",
"devDependencies": {
"eslint": "^6.7.0",
"eslint-config-prettier": "^6.7.0",
"eslint-plugin-node": "^10.0.0",
"eslint-plugin-prettier": "^3.1.1",
"jest": "^24.9.0",
"prettier": "^1.19.1",
"prettier-plugin-svelte": "^2.1.6",
"strip-ansi": "^6.0.0",
"stylelint": "^9.5.0",
"stylelint-config-prettier": "^7.0.0",
"svelte": "^3.34.0"
},
"engines": {
"node": ">=6"
},
"files": [
"stylelint-prettier.js",
"recommended.js",
"README.md",
"LICENSE.md"
],
"homepage": "https://github.com/prettier/stylelint-prettier#readme",
"jest": {
"setupFiles": [
"./jest-setup.js"
]
},
"keywords": [
"stylelint",
"stylelint-plugin",
"prettier"
],
"license": "MIT",
"main": "stylelint-prettier.js",
"name": "stylelint-prettier",
"peerDependencies": {
"prettier": ">= 0.11.0",
"stylelint": ">= 9.2.1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/prettier/stylelint-prettier.git"
},
"scripts": {
"format": "yarn run prettier '**/*.{js,json,md}' --write && yarn run lint --fix",
"lint": "eslint .",
"test": "yarn run lint && jest"
},
"version": "1.2.0"
}
+5
View File
@@ -0,0 +1,5 @@
module.exports = {
plugins: ['.'],
extends: ['stylelint-config-prettier'],
rules: {'prettier/prettier': true},
};
+260
View File
@@ -0,0 +1,260 @@
const stylelint = require('stylelint');
const {
showInvisibles,
generateDifferences,
} = require('prettier-linter-helpers');
const {INSERT, DELETE, REPLACE} = generateDifferences;
let prettier;
const ruleName = 'prettier/prettier';
const messages = stylelint.utils.ruleMessages(ruleName, {
insert: (code) => `Insert "${showInvisibles(code)}"`,
delete: (code) => `Delete "${showInvisibles(code)}"`,
replace: (deleteCode, insertCode) =>
`Replace "${showInvisibles(deleteCode)}" with "${showInvisibles(
insertCode
)}"`,
});
module.exports = stylelint.createPlugin(
ruleName,
(expectation, options, context) => {
return (root, result) => {
const validOptions = stylelint.utils.validateOptions(result, ruleName, {
actual: expectation,
});
if (!validOptions) {
return;
}
// Stylelint can handle css-in-js, in which it formats object literals.
// We don't want to run these extracts of JS through prettier
if (root.source.lang === 'object-literal') {
return;
}
const stylelintPrettierOptions = omitStylelintSpecificOptions(options);
if (!prettier) {
// Prettier is expensive to load, so only load it if needed.
prettier = require('prettier');
}
// Default to '<input>' if a filepath was not provided.
// This mimics eslint's behaviour
const filepath = root.source.input.file || '<input>';
const source = root.source.input.css;
const prettierRcOptions =
prettier.resolveConfig && prettier.resolveConfig.sync
? prettier.resolveConfig.sync(filepath, {editorconfig: true})
: null;
//prettier.getFileInfo was added in v1.13
const prettierFileInfo =
prettier.getFileInfo && prettier.getFileInfo.sync
? prettier.getFileInfo.sync(filepath, {
resolveConfig: true,
ignorePath: '.prettierignore',
})
: {ignored: false, inferredParser: null};
// Skip if file is ignored using a .prettierignore file
if (prettierFileInfo.ignored) {
return;
}
const initialOptions = {};
// If no filepath was provided then assume the CSS parser
// This is added to the options first, so that
// prettierRcOptions and stylelintPrettierOptions can still override
// the parser.
if (filepath == '<input>') {
initialOptions.parser = 'css';
}
// Stylelint supports languages that may contain multiple types of style
// languages, thus we can't rely on guessing the parser based off the
// filename.
// In all of the following cases stylelint extracts a part of a file to
// be formatted and there exists a prettier parser for the whole file.
// If you're interested in prettier you'll want a fully formatted file so
// you're about to run prettier over the whole file anyway.
// Therefore running prettier over just the style section is wasteful, so
// skip it.
const parserBlockList = [
'babel',
'flow',
'typescript',
'vue',
'markdown',
'html',
'angular', // .component.html files
'svelte',
];
if (parserBlockList.indexOf(prettierFileInfo.inferredParser) !== -1) {
return;
}
const prettierOptions = Object.assign(
{},
initialOptions,
prettierRcOptions,
stylelintPrettierOptions,
{filepath}
);
try {
prettierSource = prettier.format(source, prettierOptions);
} catch (err) {
if (!(err instanceof SyntaxError)) {
throw err;
}
let message = 'Parsing error: ' + err.message;
// Prettier's message contains a codeframe style preview of the
// invalid code and the line/column at which the error occurred.
// ESLint shows those pieces of information elsewhere already so
// remove them from the message
if (err.codeFrame) {
message = message.replace(`\n${err.codeFrame}`, '');
}
if (err.loc) {
message = message.replace(/ \(\d+:\d+\)$/, '');
}
stylelint.utils.report({
ruleName,
result,
message,
node: root,
index: getIndexFromLoc(source, err.loc.start),
});
return;
}
// Everything is the same. Nothing to do here;
if (source === prettierSource) {
return;
}
// Otherwise let's generate some differences
const differences = generateDifferences(source, prettierSource);
const report = (message, index) => {
return stylelint.utils.report({
ruleName,
result,
message,
node: root,
index,
});
};
if (context.fix) {
// Fixes must be processed in reverse order, as an early delete shall
// change the modification offsets for anything after it
const rawData = differences.reverse().reduce((rawData, difference) => {
let insertText = '';
let deleteText = '';
switch (difference.operation) {
case INSERT:
insertText = difference.insertText;
break;
case DELETE:
deleteText = difference.deleteText;
break;
case REPLACE:
insertText = difference.insertText;
deleteText = difference.deleteText;
break;
}
return (
rawData.substring(0, difference.offset) +
insertText +
rawData.substring(difference.offset + deleteText.length)
);
}, root.source.input.css);
// If root.source.syntax exists then it means stylelint had to use
// postcss-syntax to guess the postcss parser that it should use based
// upon the input filename.
// In that case we want to use the parser that postcss-syntax picked.
// Otherwise use the syntax parser that was provided in the options
const syntax = root.source.syntax || result.opts.syntax;
const newRoot = syntax.parse(rawData);
// For reasons I don't really understand, when the original input does
// not have a trailing newline, newRoot generates a trailing newline but
// it does not get included in the output.
// Cleaning the root raws (to remove any existing whitespace), then
// adding the final new line into the root raws seems to fix this
root.removeAll();
root.cleanRaws();
root.append(newRoot);
// Use the EOL whitespace from the rawData, as it could be \n or \r\n
const trailingWhitespace = rawData.match(/[\s\uFEFF\xA0]+$/);
if (trailingWhitespace) {
root.raws.after = trailingWhitespace[0];
}
return;
}
// Report in the the order the differences appear in the content
differences.forEach((difference) => {
switch (difference.operation) {
case INSERT:
report(messages.insert(difference.insertText), difference.offset);
break;
case DELETE:
report(messages.delete(difference.deleteText), difference.offset);
break;
case REPLACE:
report(
messages.replace(difference.deleteText, difference.insertText),
difference.offset
);
break;
}
});
};
}
);
function omitStylelintSpecificOptions(options) {
const prettierOptions = Object.assign({}, options);
delete prettierOptions.message;
delete prettierOptions.severity;
return prettierOptions;
}
function getIndexFromLoc(source, {line, column}) {
function nthIndex(str, searchValue, n) {
let i = -1;
while (n-- && i++ < str.length) {
i = str.indexOf(searchValue, i);
if (i < 0) {
break;
}
}
return i;
}
if (line === 1) {
return column - 1;
}
return nthIndex(source, '\n', line - 1) + column;
}
module.exports.ruleName = ruleName;
module.exports.messages = messages;