Skip to content

camelCase: 'only' and camelCase: 'dashesOnly' dont work #457

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

Closed
nikitaMe1nikov opened this issue Mar 14, 2017 · 6 comments
Closed

camelCase: 'only' and camelCase: 'dashesOnly' dont work #457

nikitaMe1nikov opened this issue Mar 14, 2017 · 6 comments
Assignees

Comments

@nikitaMe1nikov
Copy link

As I have understood from a code, these two options aren't realized.

@michael-ciniawsky
Copy link
Member

Can you link to the lines in the source code please ? :)

@michael-ciniawsky
Copy link
Member

cc @joscha

@joscha
Copy link
Contributor

joscha commented Mar 14, 2017

@nikitaMe1nikov I have 0.27.1 running here and it seems to work - can you please let us know your css-loader config and the version you are using?

@nikitaMe1nikov
Copy link
Author

My mistake, its worked. For some reason, several modules have not been upgraded

@joscha
Copy link
Contributor

joscha commented Mar 15, 2017

we should probably add a note to the docs on what version from these options are supported - or maybe we could add the same config options validation that webpack 2 has - @michael-ciniawsky what do you think?

@michael-ciniawsky
Copy link
Member

@joscha Options Validation would be optimal, but a note isn't a bad idea also 😛 . For postcss-loader I'm currently using/doing the following

npm i -S ajv // used by webpack v2

lib/validate.js

'use strict'

const Ajv = require('ajv')

class ValidationError extends Error {
  constructor (loader, err) {
    super(err)

    this.err = err
    this.message = `${loader} Validation Error\nInvalid options found:\n\n`

    err.forEach((msg) => {
      this.message += `options${msg.dataPath} ${msg.message}\n`
    })

    this.hideStack = true
  }
}

module.exports = function validateOptions (loader, schema, options) {
  const ajv = new Ajv({ allErrors: true, errorDataPath: 'property' })

  if (typeof schema === 'string') schema = require(schema)

  if (!ajv.validate(schema, options)) {
    throw new ValidationError(loader, ajv.errors)
  }
}

lib/schema.json

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "config": {
      "type": "object",
      "description": "PostCSS Config",
      "properties": {
        "path": {
          "type": "string",
          "description": "PostCSS Config Path"
        },
        "ctx": {
          "type": "object",
          "description": "PostCSS Config Context"
        }
      },
      "additionalProperties": false
    },
    "parser": {
      "type": "string",
      "description": "PostCSS Parser"
    },
    "syntax": {
      "type": "string",
      "description": "PostCSS Syntax"
    },
    "stringifier": {
      "type": "string",
      "description": "PostCSS Stringifier"
    },
    "plugins": {
      "description": "PostCSS Plugins"
    },
    "sourceMap": {
      "type": "string",
      "description": "Sourcemaps"
    },
    "exec": {
      "type": "boolean"
    },
    "rewrite": {
      "type": "boolean"
    }
  },
  "additionalProperties": false
}

index.js

...
const validateOptions = require('./lib/validate')

const LoaderError = require('./lib/error')

module.exports = function (css, map) {
  const loader = this

  const cb = loader.async()
  const file = loader.resourcePath

  const options = loaderUtils.getOptions(loader) || {}

  validateOptions('PostCSS Loader', './schema', options)
...

loader validation error

⚠️ This should ideally be part of schema-utils and then used instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants