Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Follow stylelint-config-recommended-scss v6 #29

Merged
merged 5 commits into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions lib/get-module-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"use strict"

const path = require("path")

/**
* Gets the module version from package name
*/
module.exports = function getModuleVersion(...moduleNames) {
const packageName = moduleNames.pop()

let ownerModuleRootPath = process.cwd()
for (const ownerNames of moduleNames) {
ownerModuleRootPath =
getModuleRootPath(ownerNames, ownerModuleRootPath) ||
ownerModuleRootPath
}
try {
const m = require("module")
const relativeTo = path.join(ownerModuleRootPath, "__placeholder__.js")
// eslint-disable-next-line node/no-unsupported-features/node-builtins -- ignore
return m.createRequire(relativeTo)(`${packageName}/package.json`)
.version
} catch {
// ignore
}
try {
return require(`${packageName}/package.json`).version
} catch {
// ignore
}

return null
}

/**
* Get module root path
*/
function getModuleRootPath(packageName, ownerModuleRootPath) {
try {
const m = require("module")
const relativeTo = path.join(ownerModuleRootPath, "__placeholder__.js")

return path.dirname(
// eslint-disable-next-line node/no-unsupported-features/node-builtins -- ignore
m.createRequire(relativeTo).resolve(`${packageName}/package.json`),
)
} catch {
// ignore
}
try {
return path.dirname(require.resolve(`${packageName}/package.json`))
} catch {
// ignore
}

return null
}
10 changes: 10 additions & 0 deletions lib/vue-specific-rules-for-scss.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"use strict"

const baseRules = require("./vue-specific-rules")

module.exports = {
...baseRules,
...(baseRules["function-no-unknown"]
? { "function-no-unknown": null }
: {}),
}
25 changes: 2 additions & 23 deletions lib/vue-specific-rules.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,8 @@
"use strict"

const path = require("path")
const getModuleVersion = require("./get-module-version")
const semver = require("semver")
let stylelintVersion = null
try {
const m = require("module")
const cwd = process.cwd()
const relativeTo = path.join(cwd, "__placeholder__.js")
// eslint-disable-next-line node/no-unsupported-features/node-builtins -- ignore
stylelintVersion = m.createRequire(relativeTo)(
"stylelint/package.json",
).version
} catch {
// ignore
}
if (stylelintVersion == null) {
try {
stylelintVersion = require("stylelint/package.json").version
} catch {
// ignore
}
}
if (stylelintVersion == null) {
stylelintVersion = "14.5.0"
}
const stylelintVersion = getModuleVersion("stylelint") || "14.5.0"

module.exports = {
"selector-pseudo-class-no-unknown": [
Expand Down
2 changes: 1 addition & 1 deletion scss/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
"stylelint-config-recommended-scss",
"stylelint-config-html",
],
rules: require("../lib/vue-specific-rules"),
rules: require("../lib/vue-specific-rules-for-scss"),
},
],
}
1 change: 1 addition & 0 deletions tests/fixtures/integrations/function-no-unknown/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
15 changes: 15 additions & 0 deletions tests/fixtures/integrations/function-no-unknown/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "stylelint-config-recommended-vue-test-stylelint",
"private": true,
"version": "1.0.0",
"description": "",
"devDependencies": {
"postcss-html": "^1.0.0",
"stylelint": "^14.5.0",
"stylelint-config-recommended": "^7.0.0",
"stylelint-config-recommended-vue": "file:../../../../stylelint-config-recommended-vue-test.tgz"
},
"engines": {
"node": "^12 || >=14"
}
}
14 changes: 14 additions & 0 deletions tests/fixtures/integrations/function-no-unknown/src/valid.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<style>
a {
color: v-bind(color);
}

:global(.foo),
::v-deep(.foo),
::v-slotted(.foo),
::v-global(.foo),
:deep(.foo),
:slotted(.foo) {
color: red;
}
</style>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"use strict"

module.exports = {
extends: "stylelint-config-recommended-vue",
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"postcss-html": "^1.0.0",
"stylelint": "^14.0.0",
"stylelint-config-recommended-scss": "^5.0.2",
"stylelint-config-recommended-vue": "file:../../../../",
"stylelint-config-recommended-vue": "file:../../../../stylelint-config-recommended-vue-test.tgz",
"stylelint-config-standard-scss": "^3.0.0"
},
"engines": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<style lang="scss">
a {
color: red;
color: v-bind(color);
}

// SCSS
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/integrations/stylelint-scss-v4.1/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
16 changes: 16 additions & 0 deletions tests/fixtures/integrations/stylelint-scss-v4.1/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "stylelint-config-recommended-vue-test-stylelint",
"private": true,
"version": "1.0.0",
"description": "",
"devDependencies": {
"postcss-html": "^1.0.0",
"stylelint": "^14.0.0",
"stylelint-config-recommended-scss": "^5.0.2",
"stylelint-config-recommended-vue": "file:../../../../stylelint-config-recommended-vue-test.tgz",
"stylelint-scss": "4.1.0"
},
"engines": {
"node": "^12 || >=14"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<style lang="scss">
a {
@if $x == null {
color: red;
}
}
</style>
32 changes: 32 additions & 0 deletions tests/fixtures/integrations/stylelint-scss-v4.1/src/valid.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<style lang="scss">
a {
color: v-bind(color);
padding-right: math.div(4, 2);
}

// SCSS
.b {
// stylelint-disable-next-line scss/at-if-no-null
@if $x == null {
color: red;
}
}
@mixin my-mixin {
color: blue
}

.c {
@include my-mixin
}

// Vue
:global(.foo),
::v-deep(.foo),
::v-slotted(.foo),
::v-global(.foo),
:deep(.foo),
:slotted(.foo) {
color: red;
}

</style>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"use strict"

module.exports = {
extends: "stylelint-config-recommended-vue/scss",
}
4 changes: 2 additions & 2 deletions tests/fixtures/integrations/stylelint-scss/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"devDependencies": {
"postcss-html": "^1.0.0",
"stylelint": "^14.0.0",
"stylelint-config-recommended-scss": "^5.0.2",
"stylelint-config-recommended-vue": "file:../../../../"
"stylelint-config-recommended-scss": "^6.0.0",
"stylelint-config-recommended-vue": "file:../../../../stylelint-config-recommended-vue-test.tgz"
},
"engines": {
"node": "^12 || >=14"
Expand Down
3 changes: 2 additions & 1 deletion tests/fixtures/integrations/stylelint-scss/src/valid.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<style lang="scss">
a {
color: red;
color: v-bind(color);
padding-right: math.div(4, 2);
}

// SCSS
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/integrations/stylelint-v14.3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"postcss-html": "^1.0.0",
"stylelint": "14.3.0",
"stylelint-config-recommended": "^6.0.0",
"stylelint-config-recommended-vue": "file:../../../../stylelint-config-recommended-vue-1.3.0.tgz"
"stylelint-config-recommended-vue": "file:../../../../stylelint-config-recommended-vue-test.tgz"
},
"engines": {
"node": "^12 || >=14"
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/integrations/stylelint-v14.3/src/valid.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<style>
a {
color: red;
color: v-bind(color);
}

:global(.foo),
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/integrations/stylelint-v14.4/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"postcss-html": "^1.0.0",
"stylelint": "14.4.0",
"stylelint-config-recommended": "^7.0.0",
"stylelint-config-recommended-vue": "file:../../../../stylelint-config-recommended-vue-1.3.0.tgz"
"stylelint-config-recommended-vue": "file:../../../../stylelint-config-recommended-vue-test.tgz"
},
"engines": {
"node": "^12 || >=14"
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/integrations/stylelint-v14.4/src/valid.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<style>
a {
color: red;
color: v-bind(color);
}

:global(.foo),
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/integrations/stylelint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"devDependencies": {
"postcss-html": "^1.0.0",
"stylelint": "^14.5.0",
"stylelint-config-recommended-vue": "file:../../../../",
"stylelint-config-recommended": "^7.0.0"
"stylelint-config-recommended": "^7.0.0",
"stylelint-config-recommended-vue": "file:../../../../stylelint-config-recommended-vue-test.tgz"
},
"engines": {
"node": "^12 || >=14"
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/integrations/stylelint/src/valid.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<style>
a {
color: red;
color: v-bind(color);
}

:global(.foo),
Expand Down
80 changes: 0 additions & 80 deletions tests/lib/for-old-stylelint.js

This file was deleted.

Loading