Skip to content

Commit

Permalink
Implement stylelint-config-html
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi committed Oct 19, 2021
1 parent 6201aee commit 2c269a0
Show file tree
Hide file tree
Showing 26 changed files with 520 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/.nyc_output
/coverage
node_modules
!/.vscode
!/.github
15 changes: 15 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"use strict"

module.exports = {
parserOptions: {
sourceType: "script",
ecmaVersion: 2020,
},
extends: [
"plugin:@ota-meshi/recommended",
"plugin:@ota-meshi/+node",
"plugin:@ota-meshi/+json",
"plugin:@ota-meshi/+yaml",
"plugin:@ota-meshi/+prettier",
],
}
12 changes: 12 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# These are supported funding model platforms

github: ota-meshi
# patreon: # Replace with a single Patreon username
# open_collective: # Replace with a single Open Collective username
# ko_fi: # Replace with a single Ko-fi username
# tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
# community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
# liberapay: # Replace with a single Liberapay username
# issuehunt: # Replace with a single IssueHunt username
# otechie: # Replace with a single Otechie username
# custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
35 changes: 35 additions & 0 deletions .github/workflows/NodeCI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: CI

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16
- name: Install Packages
run: npm i --legacy-peer-deps
- name: Lint
run: npm run lint
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: Install Packages
run: npm i --legacy-peer-deps
- name: Test
run: npm test
26 changes: 26 additions & 0 deletions .github/workflows/NpmPublish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: publish
on:
push:
tags:
- "*"
jobs:
release:
name: check version, and release
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v2
- name: setup Node
uses: actions/setup-node@v2
with:
registry-url: "https://registry.npmjs.org"
- name: Install Packages
run: npm i --legacy-peer-deps
- name: test
run: npm run test
- name: check can npm-publish
run: npx can-npm-publish
- name: release
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"eslint.validate": [
"javascript",
"javascriptreact",
"json",
"jsonc",
"yaml"
]
}
49 changes: 48 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,49 @@
# stylelint-config-html
The shareable HTML config for Stylelint.

[![NPM license](https://img.shields.io/npm/l/stylelint-config-html.svg)](https://www.npmjs.com/package/stylelint-config-html)
[![NPM version](https://img.shields.io/npm/v/stylelint-config-html.svg)](https://www.npmjs.com/package/stylelint-config-html)
[![NPM downloads](https://img.shields.io/npm/dw/stylelint-config-html.svg)](http://www.npmtrends.com/stylelint-config-html)
[![NPM downloads](https://img.shields.io/npm/dm/stylelint-config-html.svg)](http://www.npmtrends.com/stylelint-config-html)
[![Build Status](https://github.com/ota-meshi/stylelint-config-html/workflows/CI/badge.svg?branch=main)](https://github.com/ota-meshi/stylelint-config-html/actions?query=workflow%3ACI)

> The shareable HTML (and HTML-like) config for Stylelint.
This config bundles the [`postcss-html` custom syntax](https://github.com/ota-meshi/postcss-html) and configures it.

To see this config, please read the [config itself](/index.js).

## :cd: Installation

```shell
npm install --save-dev stylelint-config-html
```

## :book: Usage

Set your `stylelint` config to:

```json
{
"extends": "stylelint-config-html"
}
```

Note: This config enables HTML (and HTML-like) syntax parsing.

If you want to enable parsing for only specific language, use each language config as follows:

```json
{
"extends": [
"stylelint-config-html/html",
"stylelint-config-html/xml",
"stylelint-config-html/vue",
"stylelint-config-html/svelte",
"stylelint-config-html/php"
]
}
```

## :lock: License

See the [LICENSE](LICENSE) file for license rights and limitations (MIT).
27 changes: 27 additions & 0 deletions html.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"use strict"

const extensions = [
// https://github.com/Microsoft/vscode/blob/master/extensions/html/package.json
".html",
".htm",
".shtml",
".xhtml",
".xht",
".mdoc",
".jsp",
".asp",
".aspx",
".jshtm",
".volt",
".ejs",
".rhtml",
]

module.exports = {
overrides: [
{
files: extensions.flatMap((ext) => [`*${ext}`, `**/*${ext}`]),
customSyntax: "postcss-html",
},
],
}
11 changes: 11 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"use strict"

module.exports = {
extends: [
require.resolve("./html.js"),
require.resolve("./vue.js"),
require.resolve("./php.js"),
require.resolve("./svelte.js"),
require.resolve("./xml.js"),
],
}
63 changes: 63 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"name": "stylelint-config-html",
"version": "0.0.0",
"description": "The shareable HTML config for Stylelint.",
"keywords": [
"stylelint",
"stylelint-config",
"html",
"vue",
"svelte",
"php",
"xml"
],
"main": "index.js",
"files": [
"index.js",
"html.js",
"vue.js",
"svelte.js",
"php.js",
"xml.js"
],
"engines": {
"node": "^12 || >=14"
},
"scripts": {
"test": "mocha \"tests/lib/**/*.js\" --reporter dot --timeout 60000",
"lint": "eslint .",
"eslint-fix": "eslint . --fix",
"preversion": "npm test && git add ."
},
"dependencies": {
"postcss-html": "^1.0.0-0"
},
"peerDependencies": {
"stylelint": ">=14.0.0"
},
"devDependencies": {
"@ota-meshi/eslint-plugin": "^0.10.0",
"eslint": "^8.0.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-json-schema-validator": "^1.2.24",
"eslint-plugin-jsonc": "^1.7.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-regexp": "~1.4.0",
"eslint-plugin-vue": "^7.18.0",
"eslint-plugin-yml": "^0.10.1",
"mocha": "^9.1.3",
"prettier": "^2.4.1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ota-meshi/stylelint-config-html.git"
},
"author": "Yosuke Ota (https://github.com/ota-meshi)",
"license": "MIT",
"bugs": {
"url": "https://github.com/ota-meshi/stylelint-config-html/issues"
},
"homepage": "https://github.com/ota-meshi/stylelint-config-html#readme"
}
19 changes: 19 additions & 0 deletions php.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"use strict"

const extensions = [
// https://github.com/Microsoft/vscode/blob/main/extensions/php/package.json
".php",
".php4",
".php5",
".phtml",
".ctp",
]

module.exports = {
overrides: [
{
files: extensions.flatMap((ext) => [`*${ext}`, `**/*${ext}`]),
customSyntax: "postcss-html",
},
],
}
17 changes: 17 additions & 0 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extends": [
"config:base",
":preserveSemverRanges",
":disableDependencyDashboard"
],
"packageRules": [
{
"updateTypes": ["minor", "patch", "pin", "digest"],
"automerge": true
},
{
"depTypeList": ["devDependencies"],
"automerge": true
}
]
}
14 changes: 14 additions & 0 deletions svelte.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"use strict"

const extensions = [
// https://github.com/sveltejs/language-tools/blob/master/packages/svelte-vscode/package.json
".svelte",
]
module.exports = {
overrides: [
{
files: extensions.flatMap((ext) => [`*${ext}`, `**/*${ext}`]),
customSyntax: "postcss-html",
},
],
}
1 change: 1 addition & 0 deletions tests/fixtures/integrations/stylelint/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
14 changes: 14 additions & 0 deletions tests/fixtures/integrations/stylelint/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "stylelint-config-html-test-stylelint",
"private": true,
"version": "1.0.0",
"description": "",
"devDependencies": {
"stylelint": "github:stylelint/stylelint#v14",
"stylelint-config-html": "file:../../../../",
"stylelint-config-recommended": "github:stylelint/stylelint-config-recommended#5a51a9d0c5695f39810ef5337118e69cfd8f3139"
},
"engines": {
"node": "^12 || >=14"
}
}
16 changes: 16 additions & 0 deletions tests/fixtures/integrations/stylelint/src/invalid.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
color: red;
}
p {
color: #00;
}
</style>
</head>
<body>
<h1>Test</h1>
</body>
</html>
5 changes: 5 additions & 0 deletions tests/fixtures/integrations/stylelint/src/invalid.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<style>
a {
color: #00;
}
</style>
16 changes: 16 additions & 0 deletions tests/fixtures/integrations/stylelint/src/valid.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
color: red;
}
p {
color: blue;
}
</style>
</head>
<body>
<h1>Test</h1>
</body>
</html>
5 changes: 5 additions & 0 deletions tests/fixtures/integrations/stylelint/src/valid.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<style>
a {
color: red;
}
</style>
5 changes: 5 additions & 0 deletions tests/fixtures/integrations/stylelint/src/valid.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<style>
a {
color: red;
}
</style>
5 changes: 5 additions & 0 deletions tests/fixtures/integrations/stylelint/src/valid.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<style>
a {
color: red;
}
</style>
Loading

0 comments on commit 2c269a0

Please sign in to comment.